Comments (1)
极速面向搜索引擎改良,自动识别source mac address
没有检查有没有bug
慎用
# !/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import sys
import signal
from scapy.all import (
get_if_hwaddr, # 获取本机网络接口的函数
getmacbyip, # 通过IP地址获取其Mac地址的函数
ARP, # 构造ARP数据包
Ether, # 构造以太网数据包
sendp, # 在第二层发送数据包
sniff # capture network traffic
)
from optparse import OptionParser #格式化用户输入的参数
# build arp response package
def build_rep(src_ipaddr, src_mac, dst_ipaddr, dst_mac ):
pkt = Ether(src=src_mac, dst=dst_mac) / ARP(hwsrc=src_mac, psrc=src_ipaddr, hwdst=dst_mac, pdst=dst_ipaddr, op=2)
return pkt
def sniff_callback(package):
global gw_mac
print("get a arp probe package from {}".format(package.src))
pkt = build_rep(src_ipaddr=package.pdst, src_mac=gw_mac, dst_ipaddr=package.psrc, dst_mac=package.hwsrc)
sendp(pkt, inter=0, iface=options.interface)
def quit(signum, frame):
print('\nYou choose to stop me.')
exit()
def main():
#自定义程序使用方法,当中的 %prog,optparse会以当前程序名的字符串来替代
usage = 'Usage: %prog [-i interface] [--gateway gateway_ip]'
#创建一个 OptionParser 对象
parser = OptionParser(usage)
#add_option 来定义命令行参数
parser.add_option('-i', dest='interface', default="dce-br", help='Specify the interface to use')
parser.add_option('--gateway',dest="gatewayip",help="gateway ip address")
global options
(options, args) = parser.parse_args()
signal.signal(signal.SIGINT, quit)
if options.interface is None or options.gatewayip is None:
parser.print_help()
print("[debug]interface value is ",options.interface)
print("[debug]gateway ip value is ",options.gatewayip)
sys.exit(1)
# get gateway mac address
global gw_mac
gw_mac = getmacbyip(options.gatewayip)
print("gateway ip address is:{}, mac address is: {}".format(options.gatewayip, gw_mac))
sniff_filter = "arp and src 0.0.0.0 and dst " + options.gatewayip
sniff(iface=options.interface, filter=sniff_filter, prn=sniff_callback)
if __name__ == '__main__':
main()
from randommark.
Related Issues (20)
- PO和MO翻译文件的那些事 HOT 2
- MySQL注入或者一些奇奇怪怪的函数变量1 HOT 1
- 瞎乱来系列:我要怎么[背/理解]这奇怪的[命令/函数]
- 对全民K歌签到接口报文分析 HOT 1
- 多行文字从css上实现ellipsis
- ssh通过密钥连接sshd提示Permission denied (publickey).
- Chrome浏览器的一些设置mark
- use jq tool to enable/disable docker live-restore feature
- docker container net namespace debug script
- Tampermonkey+腾讯课堂+超过有效期的活动课程 HOT 1
- 打发$$伸手党用的脚本 HOT 1
- Windows Subsystem marks
- nginx client_max_body_size 指令里面的size值m十进制还是二进制的
- github action + docker image
- 安卓 - 微信圈子 - 里面的视频导出
- kdig - Advanced DNS lookup utility
- 为什么不要用systemctl reload nginx重载nginx配置 HOT 5
- Fish shell下的ssh-agent现有会话探测脚本
- Nginx 反向代理请求处理耗时很久的后端
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from randommark.