def get_working_ifaces():
 if (os.getuid() != 0):
  return []
 interfaces = []
 for ifname in get_if_list():
  if (ifname == LOOPBACK_NAME):
   continue
  try:
   result = get_if(ifname, SIOCGIFFLAGS)
  except IOError as msg:
   warning(('ioctl(SIOCGIFFLAGS) failed on %s !' % ifname))
   continue
  ifflags = struct.unpack('16xH14x', result)[0]
  if (ifflags & 1):
   (fd, _) = get_dev_bpf()
   if (fd is None):
    raise Scapy_Exception('No /dev/bpf are available !')
   try:
    fcntl.ioctl(fd, BIOCSETIF, struct.pack('16s16x', ifname))
    interfaces.append((ifname, int(ifname[(-1)])))
   except IOError as err:
    pass
   os.close(fd)
 interfaces.sort((lambda (ifname_left, ifid_left), (ifname_right, ifid_right): (ifid_left - ifid_right)))
 return interfaces

def get_working_ifaces ( ) : if ( os . getuid ( ) != 0 ) : return [ ] interfaces = [ ] for ifname in get_if_list ( ) : if ( ifname == LOOPBACK_NAME ) : continue try : result = get_if ( ifname , SIOCGIFFLAGS ) except IOError as msg : warning ( ( 'ioctl(SIOCGIFFLAGS) failed on %s !' % ifname ) ) continue ifflags = struct . unpack ( '16xH14x' , result ) [ 0 ] if ( ifflags & 1 ) : ( fd , _ ) = get_dev_bpf ( ) if ( fd is None ) : raise Scapy_Exception ( 'No /dev/bpf are available !' ) try : fcntl . ioctl ( fd , BIOCSETIF , struct . pack ( '16s16x' , ifname ) ) interfaces . append ( ( ifname , int ( ifname [ ( - 1 ) ] ) ) ) except IOError as err : pass os . close ( fd ) interfaces . sort ( ( lambda ( ifname_left , ifid_left ) , ( ifname_right , ifid_right ) : ( ifid_left - ifid_right ) ) ) return interfaces
returns an ordered list of interfaces that could be used with bpf .