Port Scanning#

Warning

* Please DO NOT scan machines without the owners permission first.

Sometimes it’s useful to know which ports are open and what services a target machine is running.

Scanning Multiple Ports#

By passing a range and/or list of ports, we can connect to multiple ports one after another.

Combining this with the -v and -z options to turn on verbose and zero I/O mode, we can create a simple port scanner:

pync -vz host.example.com 20-30 80 443
py -m pync -vz host.example.com 20-30 80 443
# scan.py
import pync
pync.run('-vz host.example.com 20-30 80 443')

As you can see, you can provide a single port, a list of ports or a range of ports to scan. In this case, we scan port 20 to 30 (20,21,22…30), port 80 (http) and port 443 (https).

For example, if ports 22 and 25 are open, you should see output similar to this:

...
Connection to host.example.com 22 port [tcp/ssh] succeeded!
Connection to host.example.com 25 port [tcp/smtp] succeeded!