#!/usr/bin/env python3 # coding: utf-8 # Do ip tuntap add argus0 mode tun user to create the tun interface import os import pdb import struct import fcntl TUNSETIFF = 0x400454ca TUNSETOWNER = TUNSETIFF + 2 IFF_TUN = 0x0001 IFF_TAP = 0x0002 IFF_NO_PI = 0x1000 correct_frame = 'e'.encode() incorrect_frame = 'é'.encode() print(incorrect_frame) ethernet = bytearray([ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # source 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # destination 0x86, 0xdd, # type (IPv6) ] ) tun = os.open("/dev/net/tun", os.O_WRONLY) ifr = struct.pack('16sH', 'argus0'.encode(), IFF_TUN | IFF_NO_PI) fcntl.ioctl(tun, TUNSETIFF, ifr) fcntl.ioctl(tun, TUNSETOWNER, 1000) os.write(tun, correct_frame) os.write(tun, incorrect_frame)