Created
August 12, 2019 14:02
-
-
Save caoya171193579/f024243fba9ab88c1a694d86e326e2e7 to your computer and use it in GitHub Desktop.
python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import socket | |
ip = input('输入要扫描的IP:') | |
#输入的端口值返回的是一个字符串,使用int()将返回的字符串转为整型。 | |
kaishi_prot = int(input('输入要扫描端口的起始位置:')) | |
jieshu_prot = int(input('输入要扫描端口的结束位置:')) | |
#使用for循环结合range()函数生成一个列表对输入的扫描端口进行遍历扫描,并做异常处理。 | |
for prot in range(kaishi_prot,jieshu_prot): | |
try: | |
s = socket.socket() | |
s.settimeout(2) #连接超时为2秒 | |
s.connect((str(ip),int(prot))) | |
print('>>>开放的端口号:',prot) | |
print(s.recv(1024)) #tcp接收,可以识别常用端口对应的服务。 | |
s.close() | |
except Exception as e: | |
pass | |
#print('>>>端口未开放,可能有误报:',e) | |
print('扫描结束!') | |
运行截图,未加多线程有点慢: | |
 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment