Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How to use the netcat to have relays? Like following I tried but not working:

cd /tmp
mknod backpipe p
nc -l -p 7007 0<backpipe | nc 192.168.1.101 9001 | tee backpipe
  1. I want to receive data on 7007 must be listening mode
    $ another application is putting packets here

  2. what ever comes to 7007 I need to move to 9001 (which is also a listening port)

    $ telnet localhost 9001
    

    will show 7007 packets?

Any idea?

Optional: will it be also possible that I can put some extra header packets? to simulate http headers as image content type?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If you do:

nc -l -p 7007 | nc -l -p 9001

Then anything that comes in to port 7007 will be piped to the second netcat and be relayed to your telnet session on port 9001.

Injecting headers requires knowing the underlying protocol, at least to figure out "message" boundaries, so it's not trivial. If you know how to do it, you can inject your code to do so between the two pipes:

nc -l -p 7007 | ./my_filter | nc -l -p 9001

./my_filter will get the input on stdin, and anything it writes to stdout will show up on port 9001.

share|improve this answer
    
The first line opens, but when i connect i get this: nc: connect to 192.168.1.101 port 9001 (tcp) failed: No route to host –  YumYumYum Oct 4 '11 at 8:12
    
The lines I posted all listen on localhost, they don't try to open sockets to remote hosts. I don't see how you could get that error with what I posted. –  Mat Oct 4 '11 at 8:17
    
You are right. Thanks –  YumYumYum Oct 4 '11 at 8:30
    
Second command fails, 7007 is not able to connect. e.g: nc -l 7007 | ./my_filter | nc -l 9001 –  YumYumYum Oct 4 '11 at 8:35
    
./my_filter is a bash file trying to get stdin. –  YumYumYum Oct 4 '11 at 8:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.