1 #!/usr/bin/python
 2 
 3 import os
 4 import struct
 5 import fcntl
 6 import binascii
 7 
 8 TUNSETIFF = 0x400454ca
 9 IFF_TAP   = 0x0002
10 
11 fd = os.open("/dev/net/tun", os.O_RDWR)
12 ifs = fcntl.ioctl(fd, TUNSETIFF, struct.pack("16sH", "t%d", IFF_TAP))
13 tname = ifs[:16].strip("\x00")
14 
15 os.system("ip link set %s up" % (tname))
16 os.system("brctl addif br0 %s" % tname)
17 
18 while True :
19     data = os.read(fd, 1500)
20     d = struct.unpack('!%ds' % len(data), data)[0]
21     print binascii.hexlify(d)

 

相关文章:

  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-10-26
  • 2022-02-18
猜你喜欢
  • 2022-12-23
  • 2022-03-09
  • 2021-12-24
  • 2021-08-05
  • 2021-07-15
  • 2021-11-12
  • 2021-12-02
相关资源
相似解决方案