Scan for open ports with Python

A simple and fast port scanner written in Python.

#!/usr/bin/env python
from socket import * 
 
if __name__ == '__main__':
    target = "localhost"
    target_ip = gethostbyname(target)
    print "Scanning", target, "-", target_ip
 
    for i in range(1, 1024):
        sock = socket(AF_INET, SOCK_STREAM)
 
        result = sock.connect_ex((target_ip, i))
 
        if(result == 0) :
            print 'Port %d: OPEN' % i
        sock.close()
Categories: Python Tags: , , ,
%d bloggers like this: