欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

我自己亲自做的 dos bat 测试 ip 端口 port 连接 连通性 port test_ip_port.bat 有大用 有大大用

@echo off
setlocal

:: 设置要测试的IP地址和端口号
set "ip=192.168.0.10"
set "port=445"

:: 使用 PowerShell 测试连接并将结果赋值给变量
for /f "tokens=* delims=" %%i in ('powershell -Command "$tcpClient = New-Object System.Net.Sockets.TcpClient; $connected = $false; try { $tcpClient.Connect('%ip%', %port%); $connected = $true } catch {}; if ($connected) { 'success' } else { 'fail' }; $tcpClient.Close()"') do set "connectionResult=%%i"

:: 输出测试结果
if "%connectionResult%"=="success" (
    echo Connection successful.
    echo MsgBox "用的NST网,可以执行此命令!", vbInformation, "提示" > temp.vbs
    cscript //nologo temp.vbs
    del temp.vbs
) else (
    echo Connection failed.
    echo MsgBox "不是用的NST网,无法执行此程序!", vbInformation, "提示" > temp.vbs
    cscript //nologo temp.vbs
    del temp.vbs
)

:: 在这里你可以根据 connectionResult 变量的值执行不同的逻辑

endlocal
pause


普通分类: