9
votes
forward a TCP connection with logging using socat
Add the -v option to print out the data being transferred:
SOCAT -v -d -d TCP-LISTEN:2001,bind=127.0.0.1,fork TCP:localhost:2002
In order to write it to a file add (Windows):
1> log.log 2>&...
9
votes
How to keep socat alive using keepalive option
From the socat manpage for -t<timeout>:
When one channel has reached EOF, the write part of the other channel is shut down.
Try adding the ignoreeof option.
7
votes
Accepted
Unable to capture remote client data with nohup and socat
Explanation
It's about stdin of socat.
For a command run in the background with &, there are basically two possibilities:
If job control is disabled in the shell (this is the default for scripts),...
5
votes
Accepted
Send UDP packet and listen for replies
Like grawity said in the comment, udp: is bidirectional. So I can just use one command:
echo <packetContent> | socat -t 10 - udp:<dstIp>:<dstPort>,sp:<srcPort>
This sends the ...
5
votes
Accepted
How to make `nc` listen on a port without setting `SO_REUSEPORT`
Looking to one of the netcat source code netcat.c in the method local_listen :
ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
if (ret == -1)
err(1, ...
5
votes
Make socat listen on both IPv4 and IPv6 stacks
You can configure socat to listen on both IPv4 and IPv6 by, counter-intuitively, always use the "TCP6-LISTENER" or "UDP6-LISTENER" address forms. This causes socat to listen in a ...
3
votes
Accepted
How to send and receive an UNIX datagram with socat?
How I made it:
echo 'INPUT_DATAGRAM' | socat -b 256000 - UNIX-SENDTO:/tmp/dest.sock,bind="/tmp/source.sock"
-b option is buffer size, as the default probably is 8 KB the response datagram ...
3
votes
SOCAT on WINDOWS: why do I need pipes option for EXEC address?
The pipes option is used to force cmd.exe or powershell to use Unix style standard input and output.
3
votes
How to keep socat alive using keepalive option
If you're using a LISTEN command like OPENSSL-LISTEN, TCP-LISTEN, etc., the fork option will spin off connections to a child process so that socat can continue receiving.
Example:
socat - OPENSSL-...
3
votes
socat UDP IPv6 to IPv4 gateway results in lots of processes
I found what I need from the socat man page...
The answer is to set a timeout for UDP-based communication.
-T<timeout> Total inactivity timeout: when socat is already in the transfer loop and ...
3
votes
Accepted
socat gives "Resource temporarily unavailable" on OS X High Sierra
You can't just open a random pty and expect it to work. (Actually, you are supposed to open each of them in turn, until you find one that is free) Instead, use the proper socat syntax for it:
socat ...
3
votes
Accepted
Using socat for SOCKET-SENDTO
Most specifically, the problem was with my STDIN (hi). I mistakenly believed that STDIN was just the packet payload; however, it's actually expecting the entire packet.
Also, I discovered that ...
3
votes
SOCAT IPv4 to IPv6 Routing
After the disappointment of no comments i found a way by myself.
Following command allows to open and forward multiply Ports at once:
For TCP: echo -n 80 443 25 3389| xargs -d ' ' -I% bash -c 'socat ...
2
votes
Accepted
Linux virtual tty
1) Did you use socat as root? If yes, start socat as the same user that starts arduino, and give correct permissions for this user to whatever other devices socat uses on top of the PTY. If you don't ...
2
votes
How to DNAT local packets
I fixed this issue by run command
conntrack -F
After all of my iptables rules.
There is no need to use --phydev, just using following two rules:
iptables -t nat -A PREROUTING -s 192.168.0.1 -d 192....
2
votes
Filter stdin of process executed with socat client
The post
Sed with port forwarding in socat
recommends using a command similar to:
socat TCP-LISTEN:8002,fork SYSTEM:/path/to/replace.sh
The file replace.sh should have the execution permission.
An ...
2
votes
Increase buffer size for a specific socket on Linux
You can try applying a loader shim that intercepts the call to socket() and does a setsockopt() to change the buffer size before returning to the caller. Presumably you would apply this to the java ...
2
votes
TCP to virtual serial port with socat
Thanks @user1686, you helped me solve it, as you noted my second command was overwriting the device rather than writing to it. A virtual pair was however necessary:
sudo socat -d -d pty,link=/dev/...
1
vote
socat accepting the connection but ignoring the bytes that get sent
As it turns out /dev/tty.* vs /dev/cu.* makes all the difference here.
The log files seem to suggest that the serial device is not ready when using /dev/tty.* while it works like this when using /dev/...
1
vote
Accepted
socat TCP server bidirectional using sleep, non-interactive client returns without response. Server reports: I/O error
Socat works with half close of sockets. That means, when it receives EOF (shutdown) on one address (in your case the TCP connection) it shuts down the write channel of the second address and gives it ...
1
vote
TCP to virtual serial port with socat
Your second command doesn't open the existing /dev/ttyVA00 device; you're asking socat to create a new pty device at that location, overwriting the old one. (In TCP terms, it's not connecting to /dev/...
1
vote
Is it possible to simulate SSH remote port forwarding with socat alone?
This is possible with Socat by building a TCP gender changer.
On serverB runs a double listener that waits for connection on 9000 and then forks a sub process that waits for connection on 7000 and ...
1
vote
SOCAT on WINDOWS: why do I need pipes option for EXEC address?
I cannot tell about cmd.exe but about bash.exe/sh.exe.
On windows the network socket has one file descriptor which doesn't allow for read() calls. (see https://stackoverflow.com/questions/4778043/...
1
vote
Share ssh-agent socket or any other named pipe between windows 10 and cygwin
After reading this so answer and looking at https://github.com/jstarks/npiperelay/ I at least managed to get one direction done using socat and putty's plink (I somehow had a bit of trouble with ...
1
vote
Send UDP packet and listen for replies
If supported, use reuseaddr with both commands. They will be like
echo <packetContent> | socat - udp:<dstIP>:<dstPort>,sp=<srcPort>,reuseaddr
socat - udp-listen:<...
1
vote
Redirect only specific hosts requests, leaving a default for others
You said "with only port 80 open". If other ports are blocked by some external firewall (e.g. a router with NAT, only port 80 is forwarded to you), then a basic rule may be like:
iptables -t nat -A ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
socat × 74linux × 32
networking × 25
ipv6 × 8
bash × 7
port-forwarding × 7
tcp × 7
netcat × 7
macos × 6
ssh × 6
serial-port × 6
sockets × 6
udp × 5
terminal × 4
ipv4 × 4
windows × 3
ubuntu × 3
proxy × 3
ethernet × 3
ssh-tunnel × 3
pipe × 3
virtualbox × 2
docker × 2
wireshark × 2
forwarding × 2