Skip to content

Instantly share code, notes, and snippets.

@elimisteve
Last active August 31, 2021 14:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elimisteve/5c9bd06cce22174c41eb1ad7b6504b48 to your computer and use it in GitHub Desktop.
Save elimisteve/5c9bd06cce22174c41eb1ad7b6504b48 to your computer and use it in GitHub Desktop.
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