Python实现端口扫描
发表于:2025-02-24 作者:千家信息网编辑
千家信息网最后更新 2025年02月24日,误删了之前的shell脚本,之前的shell脚本因为扩展性不强,就打算用python来重新实现。端口扫描的方法特别多,我这里是把结果处理成json格式,交给后端的django来处理。#!/usr/bi
千家信息网最后更新 2025年02月24日Python实现端口扫描
误删了之前的shell脚本,之前的shell脚本因为扩展性不强,就打算用python来重新实现。
端口扫描的方法特别多,我这里是把结果处理成json格式,交给后端的django来处理。
#!/usr/bin/env python# -*- coding: utf-8 -*-"""Date:2018-05-14Author:BobDescription:Processing nmap scan results"""import osimport timeimport jsonimport requestsimport subprocessfrom xml.etree import ElementTree as ETurl = 'http://10.200.56.80:8000/portscan/portScanInterface/'def remove_file(del_file): if os.path.exists(del_file): os.remove(del_file) return del_filedef alive_ip(): # Detecting live ip with open('ip_subnet.txt', 'r') as f: for ip in f: ip = ip.strip() cmd = '/usr/bin/nmap -sP -PI -PT %s >> alive_ip.txt' %ip p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) print p.stdout.read(), # Scan live ip ips = [] with open('alive_ip.txt', 'r') as f: for lines in f: if lines.startswith('Nmap scan'): ip = lines.split(' ') ip = ip[4].strip() ips.append(ip) ip_str = ' '.join(ips) nmap_scan = '/usr/bin/nmap -sV -oX nmap_scan_output.xml %s > /dev/null 2>&1' %ip_str p = subprocess.Popen(nmap_scan, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) print p.stdout.read(),def deal_scan_xml(xml_file): # Processing nmap scan results bd = open(xml_file, 'r').read() root = ET.fromstring(bd) data = [] for host in root.findall('host'): # Print the number of child elements in the host tag # print len(host), # Get ip address ip_ = host[1].get('addr') # Get ports, protocols, and other information if len(host) == 5: for port in host[3][0:]: # print port port_ = str(port.get('portid')) protocol_ = str(port.get('protocol')) if port[0].tag == 'extrareasons': continue state_ = port[0].get('state') service_ = str(port[1].get('name')) product_ = str(port[1].get('product')) version_ = str(port[1].get('version')) extrainfo_ = str(port[1].get('extrainfo')) ip_ = ip_ data.append({"ip": ip_, "port": port_, "protocol": protocol_, "state": state_, "service": service_, "product": product_, "version": version_, "extrainfo": extrainfo_}) json_data = json.dumps({"detail": data}) json_data = requests.post(url, {"detail": json_data}) print json_data.textdef main(): remove_file('alive_ip.txt') remove_file('nmap_scan_output.xml') alive_ip() deal_scan_xml('nmap_scan_output.xml')if __name__ == '__main__': main()
脚本
处理
端口
扩展性
方法
格式
端的
结果
utf-8
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发项目数据
破解游戏服务器
网络安全环境宣传
数据库人民
山东济南市浪潮存储服务器供货商
教育技术学科数据库基础
甘肃微软网络技术有限公司
关于互联网科技的小说
福安应用软件开发
中科方德怎么安装数据库
软件开发 公司配的差电脑
公安sql数据库保存期限
北京租用服务器云空间
怎么设置数据库自动递增
重庆腾科互联网科技有限公司
龙岩财务软件开发
苹果手机不能创建id服务器出错
大脸猫网络技术有限公司
韶关网络安全技术
猪八戒软件开发公司
杭州互天网络技术
服务器的空间管理
计算机网络技术素材
轻工业管理软件开发公司
如何从数据库中阅读论文
汾阳医院网络安全
软件开发客户跟进流程与技巧
失落的方舟要哪个服务器
数据库 并发数
广州pdu服务器专用电源售价