# python子网拆分IP段

2022年11月23日
0 收藏 667 点赞 3,155 浏览 1203 个字
`# author: 阿辉枫情`
`import reimport structimport socketdef IPSplitBlocks(minip, maxip):    result = []    JudgeIp = re.compile(r'^(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\$')    Flage_min = JudgeIp.match(minip)    Flage_max = JudgeIp.match(maxip)    if Flage_min and Flage_max:        minip_num = socket.ntohl(struct.unpack(            "I", socket.inet_aton(str(minip)))[0])        maxip_num = socket.ntohl(struct.unpack(            "I", socket.inet_aton(str(maxip)))[0])        if minip_num > maxip_num:            print "Error:[%s,%s] IP address size is not legitimate" % (minip, maxip)            exit()        else:            step = 2**(32 - subnet) - 1            min_num = minip_num            while True:                max_num = min_num & (~step & 0xFFFFFFFF)                max_num |= step & 0xFFFFFFFF                if max_num >= maxip_num:                    minip = socket.inet_ntoa(                        struct.pack('I', socket.htonl(min_num)))                    maxip = socket.inet_ntoa(                        struct.pack('I', socket.htonl(maxip_num)))                    result.append((minip, maxip))                    break                minip = socket.inet_ntoa(                    struct.pack('I', socket.htonl(min_num)))                maxip = socket.inet_ntoa(                    struct.pack('I', socket.htonl(max_num)))                result.append((minip, maxip))                min_num = max_num + 1    else:        print "Error:[%s,%s] IP addresses are not legitimate!!!" % (minip, maxip)        exit()    return resultif __name__ == '__main__':    subnet = 24    print IPSplitBlocks("192.168.1.1","192.168.2.1",)`

python开发_常用的python模块及安装方法

Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接：http://www.codeforces.com/contest/660/problem/CDes…

zengkefu@server1:/usr/src\$ uname -aLinux server1 4.10.0-19-generic #21…

Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式，并且由于涉及到要把拍到的照片显…

Struts的使用