Quick and easy port scanner

Tags

, , , ,


This handy one line command makes for a great port scanner so you can see what is running on any machine. Using the netcat utility you can give it a number of commands but the -z option does a scan given a range of ports.

Sample usage:

# nc -z localhost 1-65535
Connection to localhost 22 port [tcp/ssh] succeeded!
Connection to localhost 80 port [tcp/http] succeeded!
Connection to localhost 199 port [tcp/smux] succeeded!
Connection to localhost 3306 port [tcp/mysql] succeeded!
Connection to localhost 4369 port [tcp/epmd] succeeded!
Connection to localhost 5000 port [tcp/commplex-main] succeeded!
Connection to localhost 5672 port [tcp/amqp] succeeded!
Connection to localhost 15672 port [tcp/*] succeeded!
Connection to localhost 35357 port [tcp/*] succeeded!
Connection to localhost 51535 port [tcp/*] succeeded!
Connection to localhost 55052 port [tcp/*] succeeded!
Connection to localhost 55672 port [tcp/*] succeeded!
#

Why do this?

The obvious use for this is to workout whats running on your machine and reduce its exposure to attack. Services that are not needed should be disabled and the packages removed so that your machine is lean as possible.

 

Netcat is one of the most versatile apps invented so mastering it is a must for all sysadmins.