1)netcat(nc)是一个简单而有用的工具,被誉为网络安全界的“瑞士军刀”,不仅可以通过使用TCP或UDP协议的网络连接读写数据,同时还是一个功能强大的网络调试和探测工具,能够建立你需要的几乎所有类型的网络连接。
2)在Linux终端窗口可以直接使用yum工具进行安装:
[root@master01 spark]# yum install nc.x86_64
3)安装完毕后,在终端模式下运行nc -help查看命令是否正常安装
[hadoop@master01 spark]$ nc -help
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]
[-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]
[-x proxy_address[:port]] [hostname] [port[s]]
Command Summary:
-4 Use IPv4
-6 Use IPv6
-D Enable the debug socket option
-d Detach from stdin
-h This help text
-i secs Delay interval for lines sent, ports scanned
-k Keep inbound sockets open for multiple connects
-l Listen mode, for inbound connects
-n Suppress name/port resolutions
-p port Specify local port for remote connects
-r Randomize remote ports
-S Enable the TCP MD5 signature option
-s addr Local source address
-T ToS Set IP Type of Service
-C Send CRLF as line-ending
-t Answer TELNET negotiation
-U Use UNIX domain socket
-u UDP mode
-v Verbose
-w secs Timeout for connects and final net reads
-X proto Proxy protocol: "4", "5" (SOCKS) or "connect"
-x addr[:port] Specify proxy address and port
-z Zero-I/O mode [used for scanning]
Port numbers can be individual or ranges: lo-hi [inclusive]
OK,安装正常。下面我们就可以使用nc -l 9999 来监听端口,并发送数据;
[hadoop@master01 spark]$ nc -lk 8888 //开启服务器连接
Hello world!
How are you?
Goodbye!
再开一台主机,进行测试:
netstat -anop |grep 8888 //在连接之前查看端口是否存在
nc localhost 8888 //连接端口进行聊天
在我的CentOS 6.4(64-bit) 环境中执行 nc -l 9999 监听命令遇到protocol not available。
[hadoop@master01 spark]$ nc -l 9999
nc: Protocol not available
解决方法如下:
# Removes the old package
yum erase nc
# Manually downloads the working package from the Official Repository
wget http://vault.centos.org/6.6/os/x86_64/Packages/nc-1.84-22.el6.x86_64.rpm
# Installs the package
rpm -iUv nc-1.84-22.el6.x86_64.rpm
另:本系统为64位操作系统,若读者使用的是i386 (32-bit),可以使用如下链接:
wget http://vault.centos.org/6.6/os/i386/Packages/nc-1.84-22.el6.i686.rpm
转载于:https://www.cnblogs.com/bigdata-stone/p/9376376.html