I'm trying to write some application code which will communicate via a TCP connection to a device. I have complete control of my application (which runs on a server to which I have SSH access) and no control of the device. At the moment my comms code is not working and I want to debug it at a binary level.
For sake of argument, let's say the server connects to port 10000 on the device.
I want to (a) listen on port 10000 on my desktop, (b) configure the server to think the device is my desktop, (c) forward any data I get on port 10000 to port 10000 on the device, and send any replies back whilst (d) logging everything going to/from the device.
Any suggestions as to how I might do this? Or some suitable terminology to Google for?
My desktop is Ubuntu and I have the luxury of a GUI there if I need it. The application is a Modbus/TCP driver for an industrial unit if anyone is interested. The protocol is simple, but binary.
On 28/10/2008 16:01:43, Mark Rogers wrote:
I want to (a) listen on port 10000 on my desktop, (b) configure the server to think the device is my desktop, (c) forward any data I get on port 10000 to port 10000 on the device, and send any replies back whilst (d) logging everything going to/from the device.
I remember many years ago I wrote something to do this. It ran under inetd which means when the program concerned gets started the connection to the client (in your case the device) is stdin/stdout so the rest of the code did socket/bind/connect to the real server, forked into two processes each in a read/write/log loop, one reading stdin and forwarding to the server the other reading from the server and sending to stdout.
I could look but this was a long time ago so I may not have the code now.
If I was in your situation these days I would first see if I could work out what was going on by getting the device and my desktop on a common LAN and then use wireshark (previously ethereal) on the desktop to sniff in promiscous mode to see what is happenning. If that failed then I'd have to try the man in the middle that you describe.
Regards, Steve.
On 28 Oct 2008, at 16:01, Mark Rogers wrote:
I want to (a) listen on port 10000 on my desktop, (b) configure the server to think the device is my desktop, (c) forward any data I get on port 10000 to port 10000 on the device, and send any replies back whilst (d) logging everything going to/from the device.
Any suggestions as to how I might do this? Or some suitable terminology to Google for?
My desktop is Ubuntu and I have the luxury of a GUI there if I need it. The application is a Modbus/TCP driver for an industrial unit if anyone is interested. The protocol is simple, but binary.
netcat may do what you want here.
http://netcat.sourceforge.net/
Cheers,
David
David Reynolds wrote:
netcat may do what you want here.
Looks like it might, thanks!
The version in the Ubuntu repos is v1.10 and the man page states quite clearly that it's just "free", no GPL or anything, whereas the version at:
.. is 0.7.1 and is GPL, so I assume that these are different versions. I'll try the one in the Ubuntu repos for now.
On Wed, 2008-10-29 at 09:14 +0000, Mark Rogers wrote:
The version in the Ubuntu repos is v1.10 and the man page states quite clearly that it's just "free", no GPL or anything, whereas the version at:
.. is 0.7.1 and is GPL, so I assume that these are different versions. I'll try the one in the Ubuntu repos for now.
The "classic" netcat is missing some features compared to the BSD version which should also be in the repros, generally I tend to install that one.
Ahh with a little more digging it seems that the sourceforge project is GNU Netcat which is as you say GPL and currently at 0.7.1.
The netcat package in ubuntu is the "classic" netcat which is free as in the public domain...this is the original and is as old as the moon.
Then the BSD Netcat was a rewrite which is under the BSD licence, this is the one that seems to get the most frequent attention. Although you could also argue that the others are just finished :)
Wayne Stallwood wrote:
Ahh with a little more digging it seems that the sourceforge project is GNU Netcat which is as you say GPL and currently at 0.7.1.
The netcat package in ubuntu is the "classic" netcat which is free as in the public domain...this is the original and is as old as the moon.
Then the BSD Netcat was a rewrite which is under the BSD licence, this is the one that seems to get the most frequent attention. Although you could also argue that the others are just finished :)
It sounds like I probably want the BSD version, then, but for the time being I'd rather stick with binaries from the repos.
Researching further off the back of netcat, I have discovered that socat is a better match for what I need. Indeed the following command: sudo socat -x TCP4-LISTEN:10000,fork,reuseaddr TCP4:192.168.100.10:10000
.. does exactly what I was after, except that for some reason the -x switch is not doing what the documentation suggests it should - it echos data correctly but does not indicate direction of data travel using > and <
In contrast, netcat seems to need scripts to be written to spawn processes when connections are made and is altogether more complicated for this task than socat. If it weren't for the pointers to netcat I'd not have found it, though, so thanks again all!