networking - ncat only works in certain scenarios

05
2014-04
  • Emil

    I tried using ncat (a “much-improved reimplementation of netcat”) to chat with a friend (and ultimately want to send a large file, but I know I can get that working once I get chat to work).

    We both have Windows.

    On my end I typed:

    ncat -l 3333
    

    On his end I had him type:

    ncat [my public IP] 3333
    

    Nothing happened on my end, while his completed with "Ncat: ." and returned to the prompt.

    I couldn't figure out what to do to fix this, so I decided, while he's busy, I'll test this out on two of my own laptops (one with Windows, the other with Linux, not sure if it should matter).

    I found the same results ("Ncat: ." then back to prompt) only when I issued

    ncat -l 3333
    

    from Linux and

    ncat [my public IP] 3333
    

    from Windows.

    The only scenario in which the chat/file-transfer did work was when I listened from Windows and did ncat [my public IP] 3333 from Linux.

    Any ideas why this is happening, and what I can do to fix it?

  • Answers
  • Freedom_Ben

    Check that there are no firewalls in the way (to check in Wireshark, verify that a TCP SYN packet arrives at the listening instance) and check that port forwarding is properly set up if you are accessing the internet through a firewall or home router. If you aren't getting a TCP SYN packet, work your way back to the originating machine until you see where it stops. If you see a TCP SYN packet incoming followed by an outgoing TCP SYN/ACK packet, make sure that packet is arriving at the originating node, and that it responds with a TCP ACK.

    Based on the fact that it works when listening from Windows and ncatting in from Linux, I would check the personal firewall settings for the firewalls on both Linux and Windows and see if they are configured differently. Make sure you allow incoming traffic on the port you are listening on (in this case 3333).

    One difference that exists with real Netcat between Linux and Windows is that in Windows there is a -L flag that causes persistent listening after a closure. This may not have anything to do with this issue, but I thought it was worth mentioning.


  • Related Question

    linux - Sending file via netcat
  • Phil

    I'm using something like this to send file from one computer to another:

    To serve file (on computer A):

    cat something.zip | nc -l -p 1234
    

    To receive file (on computer B):

    netcat server.ip.here. 1234 > something.zip
    

    My question is... can I do the opposite? Let's say I have file on computer B and I want to send it to A but not the way I wrote above, but by making computer that's supposed to receive file (A) be 'listening' server and connect computer that's 'sending' file (B) to server and send the file? Is it possible? I think it might be but I'm not sure how to do this.

    In case my above explanation is messed up: How do I send file TO 'server' instead of serving the file on server and then taking it FROM it (like I did above)?


  • Related Answers
  • martinwguy

    On your server (A):

    nc -l -p 1234 -q 1 > something.zip < /dev/null
    
    On your "sender client" (B):
    cat something.zip | netcat server.ip.here 1234
    

  • DaveParillo

    Start another instance of netcat on computer B. Just do what you did on computer A, but serve it from B. Give the new server a new port.