多功能的网络工具软件-SOCAT介绍
2012-06-15 17:21:36 来源:我爱运维网 评论:0 点击:
socat是一个多功能的网络工具软件,名字来由是 SOcket CAT,因此可以看出它基于socket,能够折腾socket相关的无数事情。当然这些都不是我...
《Port Forwarding in user space [INFO]》和《How to forward port in user space using socat》
socat其实可以看作是netcat的加强N倍版,因此乍一看
于是,对应的命令就是:
1 | socat -d -d -lf /var/log/socat.log TCP4-LISTEN:15000,reuseaddr, |
1 2 3 4 5 6 7 8 |
# Configuration for /etc/init.d/socat # File: /etc/socat.conf SOCAT_ARGS="-d -d -d -lf /var/log/socat.log" AUTOSTART="wesnoth wesnoth6" SOCAT_wesnoth="TCP-LISTEN: |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#!/sbin/runscript # Copyright 1999-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 BIN=/usr/bin/socat SOCAT_CONF=/etc/socat.conf SOCAT_ARGS="-d -d -lf /var/log/socat.log" [ ! -f $SOCAT_CONF ] || source $SOCAT_CONF [ -x $BIN ] || exit 0 depend() { need net } start() { ebegin "Starting ${SVCNAME}" if test "x$AUTOSTART" = "xnone" -o -z "x$AUTOSTART" ; then ewarn "Autostart is set to 'none', so disabled." exit 0 fi for FORWARD in $AUTOSTART ; do ARGS=`eval echo \\\$SOCAT_$FORWARD` PID="/var/run/${SVCNAME}/$ start-stop-daemon -b --start --exec ${BIN} --make-pidfile --pidfile "${PID}" -- ${SOCAT_ARGS} ${ARGS} & done eend $? "Check ${SOCAT_LOG} to see why startup failed" } stop() { ebegin "Stopping ${SVCNAME}" for PID in /var/run/${SVCNAME}/*.pid; do start-stop-daemon --stop --quiet --exec ${BIN} --pidfile "${PID}" done eend $? } # vim: set ts=4 : |
1 | /etc/init.d/socat start |
1 | /etc/init.d/socat stop |
1 | rc-update add socat boot |
不过,依旧有一些问题。例如我首先使用 TCP4-LISTEN:15000 绑定了一个IPv4的TCP监听后,接着使用 TCP6-LISTEN:15000 绑定则会提示失败:
1 2 3 |
# socat -d -d TCP6-LISTEN:15000,reuseaddr, 2010/09/29 23:19:42 socat[3166] E bind(3, {AF=10 [0000:0000:0000:0000:0000: 2010/09/29 23:19:42 socat[3166] N exit(1) |
1 2 3 4 5 6 7 |
# netstat -an | grep LISTEN tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:15000 0.0.0.0:* LISTEN tcp6 0 0 :::21 :::* LISTEN |
分享到:
收藏