netcat創(chuàng)建TCP server和TCP client連接
- 安裝netcat
$ sudo yum install netcat
- 啟動TCP server
$ nc -l <port>
- 啟動TCP client連接
$ echo "Hello" | nc localhost <port>
如果只發(fā)送一個消息則:
$ 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
< ...