I need some tool like this one (called "TCP Test Tool") for Linux. I need not a GUI (i.e. GUI/CLI -- this is not so important), but I need to be able to make a server which can listen at any port, receive and send a raw (i.e. a hex dump) data.
4 Answers
try nc
from man nc
nc — arbitrary TCP and UDP connections and listens
-
I know about it. But how can I to receive and send a raw (hex) data interactively? I.e. I need to start a server, then send some data to it (using nc or other soft), see what was received and send a (raw) answer back. May you give me an example please?Serge Roussak– Serge Roussak2015-10-15 12:48:56 +00:00Commented Oct 15, 2015 at 12:48
socat is a sophisticated tool to connect, bidirectionally, almost anything to almost anything else. In particular, you can get it to listen on a port for connections, run a program when connected, send the data to it, and return output back to the socket. Eg:
socat TCP4-LISTEN:3344,reuseaddr,fork EXEC:/tmp/runme,pty
will run a script /tmp/runme eg:
#!/bin/bash
trap 'echo sigterm >&2;exit' TERM
echo "start" >&2
while read line
do echo "got $line"
done
in which you can do what you like with the data, such as here
returning it with the prefix "got ". You can test this with, eg, telnet localhost 3344 or
echo hi | socat - TCP4:localhost:3344
If you need to do the same with udp you can instead try, eg:
socat UDP-RECVFROM:3344,fork EXEC:/tmp/runme,pty
you will only be passed one packet, but you still get any reply. Test it with, eg:
echo hi | socat - UDP-SENDTO:localhost:3344
If all you want to do is get your data echoed back, this feature is built into xinetd, and you only need enable the echo service. See man xinetd.conf.
If you want to get bandwidth statistics, look at the netperf tool.
-
Thank you. It seems I wrote my question unclearly. I bypassed that I want to get a hex dump and to type a hex and send corresponding binary data back. So, I investigated the socat a little in a last days and it seems it is a good stuff for my issue, but it have not a hex i/o. So it needs an external tool/script to do this conversion. Maybe could you suggest it?Serge Roussak– Serge Roussak2015-10-16 18:33:03 +00:00Commented Oct 16, 2015 at 18:33
-
You can pipe the raw data into
xxd -pto get long lines of hex, and for the reverse pipe intoxxd -r -pto convert hex lines into data.meuh– meuh2015-10-16 18:39:08 +00:00Commented Oct 16, 2015 at 18:39 -
I know about it too, but it waits the eof so it is inconvenient for my task. I think there's need to write a little script or a program in C.Serge Roussak– Serge Roussak2015-10-16 18:46:02 +00:00Commented Oct 16, 2015 at 18:46
You might be interested in sendip, its website: http://snad.ncsl.nist.gov/ipv6/sendip.html
From the site:
Q: How are string and numeric arguments handled? A: Many of the header fields, and the packet data area, can be specified via the following syntax:
- 0xXXXX - interpreted as a number in hex, converted to a binary number in network byte order.
- 0XXXX - interpreted as a number in octal, converted to a binary number in network byte order.
- rN - N "random" bytes
- zN - N nul (zero) bytes
- fF - read the argument from the next line in file F
- other - taken as a literal string
-
May be, but as far as I understood sendip can not be a server.Serge Roussak– Serge Roussak2015-10-16 06:34:45 +00:00Commented Oct 16, 2015 at 6:34