code: def activate_network_interface(iface):
      
      iface = iface.encode()
  
      SIOCGIFFLAGS = 0x8913 # /usr/include/bits/ioctls.h
      SIOCSIFFLAGS = 0x8914 # /usr/include/bits/ioctls.h
      IFF_UP = 0x1 # /usr/include/net/if.h
  
      # We need to use instances of "struct ifreq" for communicating with the kernel.
      # This struct is complex with a big contained union, we define here only the few necessary
      # fields for the two cases we need.
      # The layout is given in the format used by the struct module:
      STRUCT_IFREQ_LAYOUT_IFADDR_SAFAMILY = b"16sH14s" # ifr_name, ifr_addr.sa_family, padding
      STRUCT_IFREQ_LAYOUT_IFFLAGS = b"16sH14s" # ifr_name, ifr_flags, padding
  
      sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IP)
      try:
          # Get current interface flags from kernel
          ifreq = struct.pack(STRUCT_IFREQ_LAYOUT_IFADDR_SAFAMILY, iface, socket.AF_INET, b'0' * 14)
          ifreq = fcntl.ioctl(sock, SIOCGIFFLAGS, ifreq)
          if_flags = struct.unpack(STRUCT_IFREQ_LAYOUT_IFFLAGS, ifreq)[1]
  
          # Set new flags
          ifreq = struct.pack(STRUCT_IFREQ_LAYOUT_IFFLAGS, iface, if_flags | IFF_UP, b'0' * 14)
          fcntl.ioctl(sock, SIOCSIFFLAGS, ifreq)
      finally:
          sock.close()
docs: Bring up the given network interface.
      @raise OSError: if interface does not exist or permissions are missing