发布时间:2019-09-15 09:55:57编辑:auto阅读(2380)
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
上一篇: Windows PowerShell:(
下一篇: 2月第3周新闻回顾:华为收购3Com失败
47846
46397
37285
34736
29317
25974
24918
19952
19548
18031
5794°
6419°
5930°
5963°
7067°
5913°
5947°
6440°
6405°
7782°