netcat – a handy port scan and more

Here’s a quick and easy way to check if a server port is open to connections..

nc -zv somehost 22

Connection to somehost 22 port [tcp/ssh] succeeded!

To check a range of ports you can do this..

nc -zv somehost 20-25

nc: connect to somehost 20 port (tcp) failed: Connection refused
nc: connect to somehost 21 port (tcp) failed: Connection refused
Connection to somehost 22 port [tcp/ssh] succeeded!
nc: connect to somehost 23 port (tcp) failed: Connection refused
nc: connect to somehost 24 port (tcp) failed: Connection refused
Connection to somehost 25 port [tcp/smtp] succeeded!

You can also use netcat to listen on a port (nc -l 1234) and then connect to that port with netcat from elsewhere. You can even use netcat to transfer files/data between servers and do all sorts of other useful stuff – check the ‘man’ for details!

 

You may also like...