Skip to content

Instantly share code, notes, and snippets.

@elimisteve elimisteve/ncat.md
Last active Aug 28, 2018

Embed
What would you like to do?
ncat tricks/examples

ncat trick #1

Run these in 2 terminals, after ncat is installed:

$ ncat -l -p 9999

And on the other one:

$ echo Hello | ncat localhost 9999

ncat trick #2

$ ncat -l -p 9999

This command tells ncat to listen on port 9999. We could have chosen any port between 1025 and 65535 that another program isn't already listening on.

In another terminal:

$ cat ~/.bashrc | ncat localhost 9999

This command sends the contents of your ~/.bashrc file over a TCP connection to your computer's port 9999 -- which of course your first terminal is listening on.

Bonus: tcpdump

To view this traffic flow over the (loopback) network interface, use tcpdump:

$ sudo tcpdump -vXxns 0 -i lo 'port 9999' 

ncat trick #3: visit a website

$ echo -e 'GET / HTTP/1.1\r\n\r\n' | ncat checkip.dyndns.org 80

Notice that if you visit http://checkip.dyndns.org in your browser, then right-click and View Source, you'll see that the body of the web page you visited matches the end of ncat's output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.