
Socat UNIX-LISTEN:/tmp/.X11-unix/X1,fork \

raw and echo set ttyS0's terminal parameters to practicable values, crnl converts to correct newline characters.
#Linux socat tutorial serial
Opens an interactive connection via the serial line, e.g. Socat makes alias1 your local source address (bind), cares for correct network line termination (crnl) and sends at most 512 data bytes per packet (mss). Because mail.sh inherits stdin and stdout while socat does not use them, the script can read a mail body from stdin. The fdin and fdout options tell socat to use these FDs for communication with the program. It is programmed to "speak" SMTP on its FDs 3 (in) and 4 (out). Mail.sh is a shell script, distributed with socat, that implements a simple SMTP client. Socat and myscript communicate via a pseudo tty (pty) myscripts stderr is redirected to stdout, so its error messages are transferred via socat to the connected client. For EXECuting the program, the child process chroots to /home/sandbox, sus to user sandbox, and then starts the program /home/sandbox/bin/myscript. The client must match the rules for daemon process name "script" in /etc/hosts.allow and /etc/ny, otherwise it is refused access (see "man 5 hosts_access"). Socat TCP4-LISTEN:5555,fork,tcpwrap=script \ĮXEC:/bin/myscript,chroot=/home/sandbox,su-d=sandbox,pty,stderrĪ simple server that accepts connections (TCP4-LISTEN) and forks a new child process for each connection every child acts as single relay. Further logging is directed to syslog with facility local2. With -lmlocal2, socat logs to stderr until successfully reaching the accept loop. It provides a little security by sudoing to user nobody after forking it only permits connections from the private 10 network (range) due to reuseaddr, it allows immediate restart after master processes termination, even if some child sockets are not completely shut down. This example handles an almost arbitrary number of parallel or consecutive connections by forking a new process after each accept(). TCP4:TCP port forwarder, each side bound to another local IP address (bind). With TCP4-LISTEN it listens on local port "socat -d -d -lmlocal2 \ Socat TCP4-LISTEN:Installs a simple TCP port forwarder. The port is specified by service name (www), and correct network line termination characters (crnl) instead of NL are used. http_history socat prints messages about progress (-d -d). TCP4:This is similar to the previous example, but you can edit the current line in a bash like manner (READLINE) and use the history file. Socat -d -d READLINE,history=$HOME/.http_history \ The stdin terminal parameters are not changed, so you may close the relay with ^D or abort it with ^C. Socat - TCP4:Transfers data between STDIO (-) and a TCP4 connection to port 80 of host This example results in an interactive connection similar to telnet or netcat. To send file fro the server: socat TCP:hostname:port filename On the server-side: socat TCP-LISTEN:port filename Socat READLINE,history=$HOME/.cmd_history /dev/ttyS0,raw,echo=0,crnl Socat TCP-LISTEN:80,fork TCP:To forward terminal to the serial port COM1: To forward local http port to remote http port: Socat /dev/ttyS0,raw,echo=0,crnl /dev/ttyS1,raw,echo=0,crnl So, the backpipe command works very well in those cases.To link serial port ttyS0 to another serial port: Netcat comes in many Unix and Linux distributions, but is compiled to not use ‘–e’ option.

Note that it is equivalent to nc –l –p -e /bin/bash |nc next-server-hop What happens above is that nc client initiates the connection with the listener in nc-l –p 0backpipe. Create a file: echo testing > testPush.txt.Pushing a file to Listener from client: This includes pushing a file to the listener from the client.In this type of transfer, the file is actually pulled from a listener. Pulling a file from Listener from client.Netcat can be used to transfer files between machines.

Now that we have a clear idea of Netcat syntax, let’s focus on the main subject of this article – use cases. For example, w indicates to wait for 5 seconds before timeout.
