美文网首页生产力
socat的介绍与使用

socat的介绍与使用

作者: 无处安放的躁动 | 来源:发表于2019-01-29 11:41 被阅读194次

什么是socat?

socat 是一个实用的命令行工具。


常用方法

端口转发

# 端口转发
#socat -d -d -lf /var/log/socat.log TCP4-LISTEN:6666,bind=127.0.0.1,reuseaddr,fork TCP:127.0.0.1:3306
#mysql -uroot -h127.0.0.1 -P6666 -p

文件写入

#不使用group则默认当前用户
socat -T 2 -u - CREATE:./james,group=test,perm=0640 
socat -t 2 -u - CREATE:./james,perm=0640

读取文件

socat - /tmp/jamestest
socat - GOPEN:./james
socat - OPEN:./james

socat调用命令

socat - EXEC:ls


后续补充

详细操作参数介绍

socat [options] <bi-address> <bi-address>

options

  • -V print version and feature information to stdout, and exit

将版本和功能信息打印到stdout,然后退出

  • -h|-? print a help text describing command line options and addresses

打印帮助信息

  • -hh like -h, plus a list of all common address option names

打印比-h更详细的帮助信息

  • -hhh like -hh, plus a list of all available address option names

打印最详细的帮助信息

  • -d increase verbosity (use up to 4 times; 2 are recommended)

多个使用-d 打印fatal, error, warning, notice, info, and debug messages日志级别(建议使用两个-d,最多使用4个-d)

  • 通过-d -d 显示调试信息
  • -D analyze file descriptors before loop

在开始传输阶段之前记录有关文件描述符的信息

  • -ly[facility] log to syslog, using facility (default is daemon)

将消息写入syslog而不是stderr; 使用-d选项定义的严重性。 使用可选的<facility>,可以选择syslog类型,默认为“daemon”。 第三方库可能不遵守此选项

auth, authpriv:与认证有关的系统,例如 login, su 等需要user names and passwords的服务
uucp: UUCP系统
daemon:与各个 daemon 有关的系统
kern :核心(kernel)系统
lpr:列印相关的系统
mail:与邮件相关的系统
news:与新闻群组相关的系统
syslog:与 syslogd本身相关的系统
user:一般使用者的系统
local0 ~ local7:保留, 做為特別设定使用的

参考文件

  • -lf<logfile> log to file

将消息写入<logfile> [filename]而不是stderr。 某些第三方库,特别是libwrap,可能不遵守此选

  • -ls log to stderr (default if no other log)

将消息写入stderr(这是默认值)。 某些第三方库可能不遵守此选项,特别是libwrap似乎只记录到syslog。屏幕输出

  • -lm[facility] mixed log mode (stderr during initialization, then syslog)

混合日志输出模式

  • -lp<progname> set the program name used for logging

覆盖错误消息中打印的程序名称,用于构造环境变量名称。

  • -lu use microseconds for logging timestamps

使用微秒记录时间戳

  • -lh add hostname to log messages

增加hostname到日志文件中

  • -v verbose data traffic, text

详细的数据流量,文本

  • -x verbose data traffic, hexadecimal

详细数据流量,十六进制

  • -b<size_t> set data buffer size (8192)

设置数据缓冲区大小(8192)

  • -s sloppy (continue on error)

遇到错误继续不退出

  • -t<timeout> wait seconds before closing second channel

关闭第二个频道前等待几秒钟

#不活跃不退出,有下一个输入下一个指令超过两秒则退出。
socat -t 2  - TCP:127.0.0.1:80 
  • -T<timeout> total inactivity timeout in seconds

不活动超时(以秒为单位),适用于UTP协议

#2s 不活跃两秒后退出
socat -T 2 - TCP:127.0.0.1:80
  • -u unidirectional mode (left to right)

单向模式(从左到右)

  • -U unidirectional mode (right to left)

单向模式(从右到左)

  • -g do not check option groups

不要检查选项组

  • -L <lockfile> try to obtain lock, or fail

如果存在lockfile,则退出并显示错误。 如果lockfile不存在,则创建它并继续,在退出时取消链接lockfile

  • -W <lockfile> try to obtain lock, or wait

如果存在lockfile,则等待直到它消失。 当lockfile不存在时,创建它并继续,在退出时取消链接lockfile。

  • -4 prefer IPv4 if version is not explicitly specified

如果没有明确指定版本,则使用ipv4

  • -6 prefer IPv6 if version is not explicitly specified

使用ipv6


参考文件

man pages

相关文章

  • socat的介绍与使用

    什么是socat? socat 是一个实用的命令行工具。 常用方法 端口转发 文件写入 读取文件 socat调用命...

  • socat使用

    转发 本地端口转向远程主机 socat TCP4-LISTEN:8888 TCP4:www.qq.com:80 如...

  • linux下载和安装rabbitmq

    Centos7 Yum安装socat yum -y install socat 下载erlang软件包,本文使用...

  • socat命令学习

    前言 socat是强大易用的工具,可以实现任意socket的转换。 使用 socat [options] opti...

  • 使用socat虚拟串口

    1、下载socat 2、虚拟串口 3、使用串口 根据步骤2创建的串口名称链接串口、2步骤进程需一直开启

  • RabbitMQ 的下载与安装(CentOS 7)

    0 文件及版本 RabbitMQ 3.6.5 erlang 18.3 socat rabbitmq是使用erlan...

  • 利用SOCAT来做端口转发

    yum install socat socat TCP4-LISTEN:8080,reuseaddr,fork T...

  • RabbitMQ安装

    安装erlang 测试是否安装成功 安装rabbitmq 安装时提示缺少socat,如下: 使用yum insta...

  • 使用Socat转发TCP和UD

    0x01 作用 主要是改善网络 假设有2台服务器,分别为1.1.1.1、2.2.2.2,在1.1.1.1服务器上使...

  • CTF中pwn题的搭建

    2017年5月11日 补:1、socat 中有参数reuseaddr,使用的时候加上这个,顾名思义,这个参数的意思...

网友评论

    本文标题:socat的介绍与使用

    本文链接:https://www.haomeiwen.com/subject/nycajqtx.html