chinanet.py 文件源码

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

项目:pychinadns 作者: faicker 项目源码 文件源码
def convert(self, net):
        parts = net.split('/')
        if len(parts) != 2:
            return (-1, -1)
        ip_s, mask_s = parts[0], parts[1]
        if ip_s and mask_s:
            try:
                ip = struct.unpack('>I', socket.inet_aton(ip_s))[0]
            except socket.error:
                return (-1, -1)
            mask = int(mask_s)
            if mask < 0 or mask > 32:
                return (-1, -1)
            hex_mask = 0xffffffff - (1 << (32 - mask)) + 1
            lowest = ip & hex_mask
            highest = lowest + (1 << (32 - mask)) - 1
            return (lowest, highest)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号