Apr 21, 2015

Python: Port Scanning

#!/usr/bin/env python
import socket

target=raw_input("Target: ")
ports = [22,80,443,8000]
#max_port=raw_input("Maximum port to scan: ")
for port in ports:
        print "============================================"
        print "Scanning to " + target + ":"+str(port)
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
                s.connect((target,port))
                s.send('Testing scan port \r\n')
                banner=s.recv(1024)
                if banner:
                        print "Port is open"+str(port)+" open: "+banner
                s.close()
        except: pass

No comments: