Sneaker's Stub – The Grey Stuff!

Using List for Port Scan in Python: Hacking with Python Series

The below program makes use of Lists in python to define different ports. It takes this list and then passes it to a scan function which checks if the port is open. This is a basic program. I have written this to show you the usage of list with port numbers. This script do not grab banner.

Let’s get on the code:

Explanation:

portnum=[21,22,23,25,80,8080] : This is the list of ports, the below code is going to scan. You can define other ports to, the ones that you want to scan.

exist=[] : It stores the open ports in this list.

def scan(portnum): functions that takes the port number to scan using socket connect.

sock.settimeout(1): sets the timeout for the socket, so the scan takes that as default time to connect.

exist.extend([i]):extend() is the function for list in python. It adds more list elements, hence extending the list. We are inserting the open ports in exist list.

The program to run takes exactly one argument which is the target address.