1 Star 0 Fork 46

solomonren/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.03.12 查找流氓DHCP服务器 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-03-12 16:46 . new file
#!/usr/bin/python3.4
# -*- coding=utf-8 -*-
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
conf.checkIPaddr = False
hw = get_if_raw_hwaddr('eno16777984')
dhcp_discover = Ether(dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0",dst="255.255.255.255")/UDP(sport=68,dport=67)/BOOTP(chaddr=hw)/DHCP(options=[("message-type","discover"),"end"])
result_raw = srp(dhcp_discover, multi=True, timeout=5, verbose=False)
result_list = result_raw[0].res
for i in range(len(result_list)):
ether_fields = result_list[i][1][0].fields
ip_fields = result_list[i][1][1].fields
dhcp_fields = result_list[i][1][3].fields
serverno = str(i + 1)
print('='*20 + 'Server' + serverno + '='*20)
print('Server' + serverno + ' MAC地址为: ' + ether_fields['src'])
print('Server' + serverno + ' IP地址为: ' + ip_fields['src'])
print('Server' + serverno + ' 操作码为: ' + str(dhcp_fields['op']))
print('Server' + serverno + ' ciaddr为: ' + dhcp_fields['ciaddr'])
print('Server' + serverno + ' giaddr为: ' + dhcp_fields['giaddr'])
print('Server' + serverno + ' yiaddr为: ' + dhcp_fields['yiaddr'])
print('Server' + serverno + ' siaddr为: ' + dhcp_fields['siaddr'])
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/solomonren/qytang_Python.git
git@gitee.com:solomonren/qytang_Python.git
solomonren
qytang_Python
qytang_Python
master

搜索帮助