Netcat (nc) is often called the Swiss army knife of networking on Linux. Let us see a few important things that we can achieve with the
nc command when we are tasked with networking on Linux.
Scan a local port number
Scanning a single port (In this case Port:80) on localhost with nc.
nc -vw1 0.0.0.0 80
Scan local port range
Scanning multiple ports (Ports:75-85) on localhost with nc.
nc -vw1 0.0.0.0 75-85
Scan a remote port
Scanning a particular port on a remote host with nc. For instance if you want to scan Port 80 of our website.
nc -vw1 hackerdays.com 80
Scan a remote port range
Scanning multiple ports on localhost with nc. For instance if you want to scan Port 75 to 85 of our website.
nc -vw1 hackerdays.com 75-85
Start a Server to listen on a local port
nc -l 4545
Simple one to one chat(data sending) client and server model
Create a Server and listen to a port on 1 computer
nc -l 0.0.0.0 4545
Connect to the port of that computer from a different computer/machine which acts as a Client (Or in this case, using my [same] machine but from another terminal instead)
nc 0.0.0.0 4545
Now you can start typing and press Enter in any of the 2 terminals, and see the data being sent to the other side.
Never end listening on a port as a Server
nc -kl 0.0.0.0 4545
Start by using nc to listen on a specific port, with output captured into a file:
nc -l 0.0.0.0 4545 > icon_copied.png
Use a second machine (Or in this case, using my [same] machine but from another terminal), connect to the ip and port of the machine where the listening
nc process is started, giving it the file to be sent:
nc 0.0.0.0 4545 < icon.png
Thanks for reading! Please do let us know if you have anything to share with us in the comment box section.
Happy Linux-ing! (Is that even a word? :wondering: )