2012-05-25 28 views
0

我們有一臺設備從空中接收802.11p MAC幀,並將它們完全更改爲串口(沒有網絡層頭),我們希望看到它們安排在Wireshark中,所以我們可以爲這個802.11p協議提供一種自制的嗅探器。我的方法(在Linux中與Python)是,打開串行端口,讀取幀,並將它們寫入wireshark將要監聽的命名管道。經過大量搜索後,我發現我必須寫入該管道的格式必須與pcap文件格式相同。我查看了一些執行pcap格式化(scapy,pcapy,dpkt)的python模塊,但是我找不到任何可以獲得純粹MAC幀的文件,並且只是以wireshark的方式將它寫入pcap格式的文件中閱讀,而不必我做所有的解析。你有什麼建議?讀取MAC幀並將其送入Wireshark

回答

0

剛剛創建一個tap device並寫入框架呢?然後,您可以像wireshark一樣嗅探tap設備,就像任何其他設備一樣。有一個示例在Python here中使用tap設備,在C here中使用較長的教程(實際上約爲tun設備)。

注:我沒有測試過這一點,但這個想法似乎是合理的......

UPDATE:這似乎是工作。它基於上述要點,但 只是從文件中讀取幀數據並將其寫入設備:

import sys 
import fcntl 
import os 
import struct 
import subprocess 

TUNSETIFF = 0x400454ca 
TUNSETOWNER = TUNSETIFF + 2 
IFF_TUN = 0x0001 
IFF_TAP = 0x0002 
IFF_NO_PI = 0x1000 

# Open TUN device file. 
tun = open('/dev/net/tun', 'r+b') 
# Tell it we want a TUN device named lars0. 
ifr = struct.pack('16sH', 'lars0', IFF_TAP | IFF_NO_PI) 
fcntl.ioctl(tun, TUNSETIFF, ifr) 
# Optionally, we want it be accessed by the normal user. 
fcntl.ioctl(tun, TUNSETOWNER, 1000) 

# Bring it up and assign addresses. 
subprocess.check_call(['ifconfig', 'lars0', 'up']) 

print 'waiting' 
sys.stdin.readline() 

# Read an IP packet been sent to this TUN device. 
packet = list(open('/tmp/packet.raw').read()) 

# Write the reply packet into TUN device. 
os.write(tun.fileno(), ''.join(packet)) 

print 'waiting' 
sys.stdin.readline() 
相關問題