netcat创建TCP server和TCP client连接
- 安装netcat
$ sudo yum install netcat
- 启动TCP server
$ nc -l <port>
- 启动TCP client连接
$ echo "Hello" | nc localhost <port>
如果只发送一个消息则:
$ echo "Hello" | nc -N localhost <port>
-N shutdown(2) the network socket after EOF on the input. Some servers require this to finish their work.
- 连接TLS端口
$ nc --ssl-cert cert.pem --ssl-key key.pem --ssl-trustfile ca.pem <server> <TLSPort>
- 通过proxy访问远程http服务
$ nc <proxy-host> <proxy-port>
CONNECT <server-host>:<host-port> HTTP/1.1
Host: <proxy-host>:<proxy-port>
< HTTP/1.0 200 Connection established
GET /tsam HTTP/1.1
Host: <server-host>:<server-port>
Accept: */*
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=UTF-8
< ...