network.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:psystem 作者: gokhanm 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号