An easy to use Python3 package that could perform port scanning conveniently.
An output example is showed as following:
pip install pyportscanner
- Clone or download this repository.
- Install the package using
python setup.py install
. - Voilà ! You are ready to go!
- Add
from pyportscanner import pyscanner
to the beginning of your code. - Initialize a new PortScanner object using
scanner = pyscanner.PortScanner(target_ports=100, timeout=10, verbose=True)
. - Then call
scanner.scan(objective)
to perform a port scan to a specific target. The target could either be an IPv4 address or a host name. - Note that the total scan time for a target website is highly related to the timeout value set for the Scanner object. Thus for the seek of efficiency, the timeout should not be too long.
class pyportscanner.pyscanner.PortScanner(target_ports=None, thread_limit=100, timeout=10, verbose=False)
PortScanner is the class provides methods to execute the port scan request. A PortScanner object is needed for performing the port scan request.
- target_ports can be a list or int. If this args is a list, then the list of ports specified by it is going to be scanned, default to all ports we have in file. If this args is an int, then it specifies the top X number of ports to be scanned based on usage frequency rank.
- thread_limit is the number of thread being used for scan.
- timeout is the timeout for the socket to wait for a response.
- verbose specifies whether the results would be print out or not. If
True
, results will be print out.
PortScanner.scan(objective, message = '')
Scan an objective with the given message included in the packets sent out.
- objective is the target that is going to be scanned. It could be an IPv4 address or a hostname.
- message is the message that is going to be included in the scanning packets sent out. If not provided, no message will be included in the packets.
An example usage case is showed in examples/PortScanExample.py.
In order to run unit test, execute the following command under the root directory.
pytest --cov pyportscanner/ tests/