Tag:python Scan Tool
[[email protected] ~]# cat portscan.py #!/usr/bin/env python# -*- coding:utf-8 -*-import socket# instantiation of an object S = socket.socket () #循环遍历你自定义的端口范围 For port in range (1,65535): #使用python的异常处理 to determine the behavior after a program error try: print "[+] attempting to connect to 127.0.0.1: " + STR (port) #客户端对服务器端进行连接, the format of the general address is a tuple (hostname,port) and returns a socket.error error if there is an error in the connection. s.connect ((' 127.0.0.1 ', port)) #发送tcp数据 s.send (' Fuweichao ') #接受TCP套接字的数据. The data is returned as a string, bufsize specifies the maximum amount of data to receive     BANNER = S.RECV (1024x768) if banner: print "[+] port " + str (Port) + " open: \n" + banner s.close () except: pass
Python knowledge points used: Socket programming, exception handling, for loop traversal, if judgment.
This article from "Shangwei Super" blog, declined reprint!
Python implements the TCP port scan Tool