简单的脚本
#coding:utf-8
from socket import *
import sys
import threading
import time
#python scan_port.py <host> <start_port>-<end_port>
lock = threading.RLock()
class INFO:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
ARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def scan_port(host, port):
s = socket(AF_INET, SOCK_STREAM)
s.settimeout(5)
try:
result = s.connect_ex((host, port))
#print result
if result == 0:
lock.acquire()
print INFO.OKBLUE+u"[+]---%s, %d 端口开放---[+] "%(host, port)+INFO.ENDC
lock.release()
else:
print INFO.WARNING+u"[+]---%s, %d 端口没有开放---[+] " % (host, port)+INFO.ENDC
#s.close()
#
except Exception, e:
raise e
if __name__ == '__main__':
#scan_port("demo.testfire.net", 80)
start_time =time.time()
if len(sys.argv) != 3:
print "python scan_port.py <host> <start_port>-<end_port>, and port must 1-65535 int"
sys.exit()
host = sys.argv[1]
ports = sys.argv[2].split('-')
#print ports
#port = ports[0]
#print len(sys.argv)
if len(ports) ==2 and (1 <= int(ports[0]) <= 65535) and (1 <= int(ports[1]) <=65535):
for p in range(int(ports[0]),int(ports[1])+1):
t = threading.Thread(target=scan_port,args=(host,p))
t.start()
#print "Finished in %.2fs" % (time.time() - start_time)
#scan_port(host, p)
elif len(ports) ==1 and len(sys.argv) == 3 and (1 <= int(ports[0]) <= 65535):
t = threading.Thread(target=scan_port,args=(host, int(ports[0])))
t.start()
else:
print "python scan_port.py <host> <start_port>-<end_port>, and port must 1-65535 int"
sys.exit()
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。