socat,一個多功能的網絡工具,名字來源於SOcket CAT,是netcat的增強版,也就是netcat++(擴展了設計,並有新的實現)。
推薦:socat官方文檔
以及 socat - Handling all Kinds of Sockets (pdf)
------------------------------------------------------------------------
0x01 安裝
# debian/ubuntu apt-get install socat # centos/redhat yum install -y socat
0x02 通過源碼安裝
在centos或者redhat通過yum安裝后的socat,運行報錯:
E parseopts(): unknown option "tcpwrap"
這里是版本沒編譯進去tcpwrap,先卸載當前socat后,再進行源碼編譯安裝:
(目前最新版本是1.7.3.3)
yum install -y tcp_wrappers tcp_wrappers-devel readline-devel openssl-devel yum install -y gcc v=1.7.3.3 wget http://www.dest-unreach.org/socat/download/socat-${v}.tar.gz tar zxvf socat-${v}.tar.gz cd socat-${v} ./configure make && make install
0x03 windows版socat
git clone https://github.com/StudioEtrange/socat-windows
(暫時不推薦用,存在各種問題)
0x04 fork EXEC
將一個使用標准輸入輸出的單進程程序變為一個使用fork方法的多進程服務
socat TCP4-LISTEN:2333,tcpwrap=script,reuseaddr,fork EXEC:"/usr/bin/env python2 -u pcat.py"
(其中TCP4-LISTEN可簡寫為tcp-l,而python -u表示輸出不緩存)
0x05 其他
socat的用途很多,可參見開頭列舉的文檔以及pdf,以后pcat有空再補充。