A Gentle Introduction to netcat

Sending TCP packets

$ echo '<YOUR MESSAGE HERE>' | nc <HOST> <PORT>
# Sending ‘hello world!’ to localhost on port 12345.
$ echo 'hello world' | nc localhost 12345

Listening to incoming TCP packets

$ nc -l <PORT>
$ nc -l 12345 # Tell netcat to listen to port 12345 for TCP packets

Sending/Receiving Files:

$ cat example-netcat.txt
hi there, netcat! # contents of example-netcat.txt
$ cat example-netcat2.txt
hi there, netcat! # which is the same as in the original file.

Port Scanning

# Scan 'host.example.com' with ports ranging from 10 to 50.
$ nc -z host.example.com 10–50

Other Options

UDP Packets

# Sending ‘hello world!’ as UDP packet(s) to localhost on port 12345.
$ echo 'hello world' | nc -u localhost 12345
$ nc -ul 12345 # Tell netcat to listen to port 12345 for UDP packets

Verbose output

$ nc -l 12345 -v # Listen on port 12345
Listening on [0.0.0.0] (family 0, port 12345) # This will be printed when verbose is enabled.

--

--

--

Hacker. Aspiring tech entrepreneur. Passionate about technological advancements for the betterment of humanity. https://zhenghaotan.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Zheng Hao Tan

Zheng Hao Tan

Hacker. Aspiring tech entrepreneur. Passionate about technological advancements for the betterment of humanity. https://zhenghaotan.com

More from Medium

Why C is the most powerful language

How I made a GUI Application in C using GTK Library.

Groot in Linux

Greatest of Three Numbers in C language