linux mac帧发送,读取MAC帧并将其发送给Wiresh

只创建一个tap device并将框架写入其中如何?然后您可以像其他任何设备一样使用wireshark嗅探tap设备。在Python here中有一个使用tap设备的例子,在Chere中有一个较长的教程(实际上是关于tun设备的)。在

NB:我还没有测试过这个,但这个想法似乎很合理。。。在

更新:这似乎有效。这是基于上述要点,但是

只需从文件中读取帧数据并将其写入设备: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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值