TCP Connect Scan using Python

nmap port port scan python scapy tcp connect vulnerability scan
##################################################################### # # Need Python version 2.x, scapy, and python module sys installed on system # Usage: python tcpConnect.py [hostname] [port] # For example: python tcpConnect.py google.com 80 # https://github.com/qasimchadhar/portScan/blob/master/tcpConnect.py # ########################################################################### from socket import * import logging logging.getLogger("scapy.runtime").setLevel(logging.CRITICAL) #Supress scapy info level messages from scapy.all import * import sys def tcpconnect(host, port): print "[+] Performing TCP Connect Scan against " + str(host) +" on port "+ str(port) + "\n"; try: dstip = host srcport = random.randint(1,65535) dstport = port tcpconnectscanresp = sr1(IP(dst=dstip)/TCP(sport = srcport,dport = dstport,flags="S"),timeout=10) if(str(type(tcpconnectscanresp))""): print("[+] Port " + str(dstport) + " is open.") elif(tcpconnectscanresp.haslayer(TCP)): if(tcpconnectscanresp.getlayer(TCP).flags 0x12): # 0x12 SYN-ACK sendrst = sr(IP(dst=dstip)/TCP(sport=srcport,dport=dstport,flags="AR"),timeout=10) print("[+] Port" + str(dstport) + " is open.") elif(tcpconnectscanresp.getlayer(TCP).flags 0x14): # 0x14 ACK-Reset print("[+] Port" + str(dstport) + " is closed.") except IOError as e: print(e) if name"main": if len(sys.argv) < 2: print "Usage: python tcpConnect.py [hostname] [port]" else: hostname = str(sys.argv[1]) portnum = int(sys.argv[2]) tcpconnect(hostname, portnum)

The author would love to hear your comments. Let us discuss at Twitter @qasimchadhar.