Kali Python3环境安装scapy模块
pip3 install scapy
本地网卡网段arp_scan脚本
#!/usr/bin/python3 import logging import subprocess logging.getLogger("scapy.runtime").setLevel(logging.ERROR) from scapy.all import * if len(sys.argv) != 2: print("使用方法 - ./arp_ping.py [interface]") print("示例 - ./arp_ping.py eth0") print("用于扫描网卡所在的C类地址段") sys.exit() interface = str(sys.argv[1]) ip = str(subprocess.check_output("ifconfig "+ interface + " | grep 'broadcast' | cut -d ' ' -f 10 | cut -d '.' -f 1-3", shell=True).strip(), encoding='utf-8') prefix = str(ip + '.')、 """过滤出网段信息,输出信息如:x.x.x.""" for addr in range(0,254): answer = sr1(ARP(pdst = prefix+str(addr)),timeout = 1, verbose = 0) if answer == None: """返回结果为空,则说明目标未响应,并继续扫描下一个,否则打印目标ip信息""" pass else: print(prefix+str(addr) + "存活")
C类网段ping_scan脚本
#! /usr/bin/python3 import logging import subprocess logging.getLogger("scapy.runtime").setLevel(logging.ERROR) from scapy.all import * if len(sys.argv) !=2: """如果输入的参数不是2个,打印输入示例,并退出""" print("使用方法: python3 ping_scan.py x.x.x.0/24") sys.exit() address = str(sys.argv[1]) prefix = address.split('.')[0] + '.' + address.split('.')[1] + '.' + address.split('.')[2] + '.' for addr in range(1,254): answer = sr1(IP(dst=prefix +str(addr))/ICMP(), timeout = 1, verbose = 0) if answer == None: pass else: print(prefix + str(addr) + "存活")
TCP扫描(通过目标ip是否有回包判断存活状态)
# usr/bin/python3 import logging logging.getLogger("scapy.runtime").setLevel(logging.ERROR) from scapy.all import * if len(sys.argv) != 2: print("使用示例:python3 ACK_ping.py 192.168.95.0") print("对192.168.95.0/24 进行TCP ACK ping 扫描") sys.exit() address = str(sys.argv[1]) prefix = address.split('.')[0] + '.' + address.split('.')[1] + '.' + address.split('.')[2] + '.' for addr in range(1,10): """对目标ip的2222端口发送 TCP ACK报文""" response = sr1(IP(dst=prefix + str(addr))/TCP(dport = 2222, flags = 'A'), timeout = 1, verbose = 0) try: if int(response[TCP].flags) == 4: """如果响应报文中的TCP flags字段为4,即目标reset连接,打印目标ip""" print(prefix + str(addr) + "存活") except: pass
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。