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
本文来自博客园,作者:Lz_蚂蚱,转载请注明原文链接:https://www.cnblogs.com/leizia/p/18066905
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步