今天打算用 nc ( netcat ) 命令做一个简单的本地监听,以测试防火墙是否封锁了某个端口。
网上很多文章上都是这样写:
nc -l -p $PORT
但是在我的 CentOS 5u4 上确实不能正确执行成功,一直提示语法错误。
后来查看 nc 的 man 手册,关于 -l 选项,里面这样写着:
-l Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host. It is an error to use this option in conjunction with the -p, -s, or -z options. Additionally, any timeouts specified with the -w option are ignored.
因此正确的写法应该是:
nc -l $PORT
这样就直接监听本地的 $PORT 端口了。
费解,不知道是不是因为 CenOS 5u4 上的 nc 版本太旧的缘故。
没有评论:
发表评论