python 编程构造并发送802.11 wifi mac帧

为了通过python编程发送mac帧测试wifi模块是否正常工作,特编写此程序

前提:需要有一个支持监控模式的网卡,并在Linux操作系统下运行该程序

# !/usr/bin/env python
# -*- coding: utf-8 -*-
# note: precondition: pip install scapy
# 1. Verify that the network card supporting monitor mode: iwconfig
# 2. nable monitor mode of wlan0: airmon-ng start wlan0
# 3. Set the channel of wlan0mon: iwconfig wlan0mon channel 

from scapy.all import *

wifi_mac_frame = RadioTap() / Dot11() / Raw()  # blank wifi mac frame

# frame header
wifi_mac_frame.type = 0  # management
wifi_mac_frame.subtype = 13  # action
wifi_mac_frame.proto = 0  # protect
wifi_mac_frame.FCfield = "retry" # retry
wifi_mac_frame.ID = 14849  # duration
wifi_mac_frame.addr1 = "FF:FF:FF:FF:FF:FF"  # broadcast address
wifi_mac_frame.addr2 = "02:3B:42:E1:FC:55"  # source address
wifi_mac_frame.addr3 = "02:3B:42:E1:FC:55"  # bssid
wifi_mac_frame.SC = 48  # sequence number

# frame body
hex_value = '042243000290fad602000000640043ef3d3d'  # FILS Discover Frame
wifi_mac_frame.load = bytes.fromhex(hex_value)  # payload

wifi_mac_frame.show()  # show frame

sendp(wifi_mac_frame, iface="wlan0mon", count=10000)  # send 10000 times

使用说明:

1、需要将代码中的addr1和addr2替换成目标AP热点的mac地址 

2、修改type和subtype的值可以构造不同类型的帧

3、sendp函数中的count参数表示发送帧的次数

特别注意:本程序只用于学习,不可用于违法目的,亦不可攻击他人正常工作的AP热点

你可能感兴趣的:(python,scapy,wifi)