bat脚本:测试列表中ip对应端口网络是否连接

ips_and_ports.txt文件内容:

127.0.0.1 8080
10.1.1.1 80
10.2.2.2 443
@echo off
chcp 65001
setlocal EnableDelayedExpansion
REM 指定文本文件路径
set "txt_file=ips_and_ports.txt"
REM 检查文件是否存在
if not exist "%txt_file%" (
echo Error: 文件 %txt_file% 不存在
exit /b 1
)
REM 读取文件的每一行并进行测试
for /f "tokens=1,* delims= " %%a in (%txt_file%) do (
set "ip=%%a"
set "ports=%%b"
echo Testing connection to IP !ip! on ports: !ports!
REM 分割端口字符串并进行测试
for %%p in (!ports!) do (
(echo exit) | telnet !ip! %%p >nul 2>nul
if errorlevel 1 (
echo IP !ip! Port %%p 无法连接
) else (
echo IP !ip! Port %%p 可以连接
)
)
)
endlocal
posted @   Lz_蚂蚱  阅读(115)  评论(0编辑  收藏  举报
(评论功能已被禁用)
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起