English 中文(简体)
阅读 MAC 框架并将其喂给 Wireshark
原标题:Reading MAC frame and feeding it to Wireshark
  • 时间:2012-05-25 17:11:44
  •  标签:
  • python
  • pcap

我们有一个装置接收了802.11p MAC框架 从空中, 并把它们喂到序列端口 完全没有变化(没有网络层信头) 我们希望看到它们安排在Wireshark, 这样我们就可以为这个802.11p协议 找到一种自制的嗅探器。

我的方法(在有皮松的Linux)是,打开序列端口,读读框架并将其写成一个有名的管道,有线人会监听。经过许多次搜索,我发现我必须写进管道的格式必须像pcap文件格式一样。我看过一些配对格式化(scapy、pcapy、dpkt)的python模块,但是我找不到任何得到纯的MAC框架的模块,只要把它写成一个以pcap格式的文件,使线人能够阅读,而不用我做所有的分割。你的建议是什么?

问题回答

建立 < a href=> "http://www.kernel.org/doc/Documentation/networking/tuntap.txt" rel=“nofollow” >tap 设备 并为此写入框架如何? 然后你可以用 tap 设备闻闻 设备,就像任何其他设备一样。在 Python < a href="https://gist.github.com/585369" 中,有一个使用

NB:我已经测试过这个,但这个想法似乎合理...

UPDATE: This seems to work. It s based on the above gist, but simply reads frame data from a file and writes it to the device:

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()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...