扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
昨天在微软的网站上看到了一个命令行方式下的端口扫描工具,down下来看了看,(你也可以到http://www.sometips.com/soft/portqry.exe下载)觉得这玩艺就操作性而言比其他同类产品差得太多,仔细一瞧,突然它居然有一个返回值的功能,这样岂不是可以在批处理文件里面来使用,呵呵,于是乎就写了个小小的脚本,希望能对大家有所帮助.
C:\scripts>type monitor.cmd
@echo off
setlocal
if {%1}=={} goto noparms
if {%2}=={} goto noparms
REM Please copy portqry.exe to the same folder with monitor.cmd.
portqry -n %1 -e %2 -q
IF %ERRORLEVEL% EQU 1 goto down
IF %ERRORLEVEL% EQU 0 goto up
:noparms
echo Usage: monitor.cmd ServerIP PortNumber
goto end
:up
echo The %2 port is listening on %1...
goto end
:down
echo The %2 port is not listening on %1...
goto end
:end
执行该脚本的结果:
C:\scripts>monitor.cmd
Usage: monitor.cmd ServerIP PortNumber
C:\scripts>monitor.cmd bbs.nsfocus.com 80
The 80 port is listening on bbs.nsfocus.com...
C:\scripts>monitor.cmd bbs.nsfocus.com 79
The 79 port is not listening on bbs.nsfocus.com...
你可以根据你自己的需要对这个脚本进行改动,Hope it helps...
附上PortQry的用法:
PortQry Usage:
PortQry.exe -n server [-p protocol] [-e || -r || -o endpoint(s)]
[-l logfile] [-s] [-q]
Where:
-n [server] IP address or name of server to query
-p [protocol] TCP or UDP or BOTH (default is TCP)
-e [endpoint] single port to query (valid range: 1-65535)
-r [end point range] range of ports to query (start:end)
-o [end point order] range of ports to query in an order (x,y,z)
-l [logfile] name of log file to create
-s 'slow link delay' waits longer for UDP replies from remote systems
-q 'quiet' operation runs with no output
returns 0 if port is listening
returns 1 if port is not listening
returns 2 if port is listening or filtered
Notes:
This version runs on Windows 2000 and Windows XP
Defaults: TCP, port 80, no log file, slow link delay off
Hit Ctrl-c to terminate prematurely
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者