Python 官方文档:入门教程 => 点击学习
'''这是一个端口全连接扫描的脚本,扫描结果会比较准确,但是比较费时间''' '''运行环境 python3 ''' from Socket import * def portScanner(host,port): try:
'''这是一个端口全连接扫描的脚本,扫描结果会比较准确,但是比较费时间'''
'''运行环境 python3 '''
from Socket import *
def portScanner(host,port):
try:
s = socket(AF_INET,SOCK_STREAM) #注意参数
s.connect((host,port)) #注意括号 (host,port)
print('[+] %d open' % port)
s.close()
except: #如果端口连接失败,则输出$port close
print('[-] %d close' % port)
def main():
setdefaulttimeout(1)
ports = [20, 22, 23, 80, 111, 3306] #定义要扫描的端口,也可以在下面定义 for p in range(1,1024):
for p in ports:
portScanner('192.168.60.130',p) #设置要扫描的主机为192.168.60.130
if __name__ == '__main__': #“Make a script both importable and executable”
main() # 如果这文件中的代码被外部的python文件调用是不会被执行的
ps: 关于Python中的 if __name__ == '__main__'
的解释可以参考:https://www.cnblogs.com/kex1n/p/5975575.html
--结束END--
本文标题: Python 端口扫描(全连接,无多线程
本文链接: https://www.lsjlt.com/news/186526.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0