def is_up(self, interface_name):
''' Return True if the interface is up, False otherwise. '''
interface_check = self.interfaces
if not interface_name in interface_check:
raise WrongInterfaceName("Wrong Interface Name %s" % interface_name)
ifname = interface_name.encode(encoding='UTF-8')
# Get existing device flags
ifreq = struct.pack('16sh', ifname, 0)
flags = struct.unpack('16sh', fcntl.ioctl(self.sock, SIOCGIFFLAGS, ifreq))[1]
# Set new flags
if flags & IFF_UP:
return True
else:
return False
评论列表
文章目录