그냥 tap device을 만들고 그것에 프레임을 씀은 어떻습니까? 그런 다음 다른 기기와 마찬가지로 tap
기기를 wireshark
으로 스니핑 할 수 있습니다. Python here에 tap
장치를 사용하고 C here에 더 긴 튜토리얼 (실제로는 tun
장치)을 사용하는 예가 있습니다.
NB : ...이 테스트를하지 않은,하지만 아이디어는 합리적인 것 같다
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()