-   Linux - Software (
-   -   connecting two machines only using netcat? (

loolooyyyy 06-14-2012 08:52 AM

connecting two machines only using netcat?
i clarified my post:
i have Machine_A and Machine_B, and want to do this
[on A]

$ mkfifo F
$ pythonscrip connect localhost port 1212
$ netcat -l -p 1209 < F | netcat MACHINE_B_IP 1313 > F

[on B]

$ mkfifo F
$ pythonscrip connect localhost port 1212
$ netcat -l -p 1209 < F | netcat MACHINE_A_IP 1313 > F

but i get the error connection refused, running these:
`An Application Keep saying Hello to port 1209` On B : simply running
`netcat -l -p 1209 < F | netcat MACHINE_A_IP 1313 > F` on B : simply running
`telnet MACHINE_B 1313` on A : error: connection refused
i do this in test environment, live arch linux, on virtual machines, no iptables service or firewall running
A is:
B is:
virtual machines have an internal network, they can ping eachother, they can SSH to each other: which means they are connected,no network problem (i guess)

jefro 06-14-2012 03:05 PM

I am not sure I understand the issue. If you want to test nc then do it from command line. Then see if you can pipe it that way.

As to how to have a nc server you might look at my favorite two links.

And we may need to know the version of nc or netcat you have. Some do not act as expected. Some embedded and busybox versions are very limited.

schneidz 06-14-2012 03:10 PM

i am also not following your scenario but i do this sometimes (maybe it will help):

[schneidz@hyper stuff]$ cat /home/schneidz/stuff/
PL=$(find /root/user/music -name "*.mp3")
NUM=$(echo $PL |wc -w)
while true; do
s=$(echo $PL |cut -d ' ' -f$r)
echo "HTTP/1.0 200 OK\nContent-Type: audio/x-mp3stream\n\n"
dd if=$s bs=1024
} | nc -l -s address -p 8020

loolooyyyy 06-14-2012 09:37 PM

i think i should apologize, i was too tired and sleepy to ask a question
i want to create a tunnel, which python scripts will use this tunnel to communicate
netcat: GNU netcat 0.7.1,
p1,p2 : py scripts , nc1,nc2 : netcat running on machine 1 and 2:
p1 <--localMachine1--> nc1 <==internet==> nc2 <--localmachine2--> p2
more simple:
p1 <--> nc1 <==> nc2 <--> p2

py script will receive and send data to netcat on port 2020 on localhost
netcat will receive and send data to other netcat on remote machine on port 3030

netcat has the option L, which is for tunneling, like this:
-L, --tunnel=ADDRESS:PORT forward local port to remote address
but when i do this on machine 1, what should i do on machine 2, so that the connection is accepted?

ps: i know i can do it using ssh flawlessly, but if you could help me do it using netcat, i'll be very grateful
ps2: thanks jefro, the cheat sheet was the only good one i've seen!
@schneidz: what does that script do?

schneidz 06-14-2012 11:09 PM

^ an example of playing a random mp3 on another computer such as a phone. i saw it as someones signature and thought it mite help in this instance.

loolooyyyy 06-14-2012 11:32 PM

it was so cool!

AwesomeMachine 06-15-2012 12:54 AM

Just use the same port to receive and send, on both machines. Networking is full duplex.

loolooyyyy 06-15-2012 04:01 AM

you mean
netcat -l -p 2020 Remote 2020?

All times are GMT -5. The time now is 11:36 AM.