前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Kali-Python scapy模块-

Kali-Python scapy模块-

作者头像
py3study
发布2020-01-07 16:03:20
9620
发布2020-01-07 16:03:20
举报
文章被收录于专栏:python3python3

Kali Python3环境安装scapy模块

代码语言:javascript
复制
pip3 install scapy

本地网卡网段arp_scan脚本

代码语言:javascript
复制
#!/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脚本

代码语言:javascript
复制
#! /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是否有回包判断存活状态)

代码语言:javascript
复制
# 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
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档