Use netcat as a nmap replacement

Subject:

 

Use netcat as a nmap replacement

The utility netcat enables you to specify a range of ports when doing port scanning. The next command tells netcat to scan the 192.168.2.1 address using a range of port numbers from 20 to 40:

$ netcat -z -v -n 192.168.2.1 20-40The –n optiontellsnetcattodisableDNS

lookupforthegivenIPaddress,whereasthe –z option tells netcat to send zero data, which makes netcat close the connection as soon as it opens it without sending any data.

Please note that you cannot use a port range to make netcat listen to multiple port numbers with just one command – in order to make netcat listen to multiple ports, you should run many netcat processes. The following script will do the trick:

#!/bin/bashfromPort=2000toPort=2100for (( i = fromPort+1; i <= toPort; i++ )) do

nc -l -k -p $i -c “nc localhost $last_port” &

donenc -l -k -p $fromPort

Note: please run this script with a great amount of caution as it might make your Linux machine run very slowly when used improperly and make sure that you test it with a small port rangefirst.Pleasealsobearinmindthat differentUnixvariantshaveslightlydifferent command line options for the many tools that we have covered in the tutorial, including the main three: netcat, netstat and lsof.

 

2016-03-03 23:10:57gstlouis