#!/usr/bin/env python3 # coding: utf-8 # Do ip tuntap add argus0 mode tun user to create the tun interface 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) with open("/dev/net/tun", "wb", buffering=0) as tun: ifr = struct.pack('16sH', 'argus0'.encode(), IFF_TUN | IFF_NO_PI) fcntl.ioctl(tun, TUNSETIFF, ifr) fcntl.ioctl(tun, TUNSETOWNER, 1000) tun.write(correct_frame) tun.write(incorrect_frame)