昨天在微软的网站上看到了一个命令行方式下的端口扫描工具,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