a_ip:10.10.15.100b_ip:10.10.15.101c_ip:10.10.10.100netmask:255.255.255.0 def numtobinary(num): binary = '' a = int(num) while 1: if a == 0 or a == 1: binary = '%s%s' % (str(a), binary) break num = a % 2 binary = '%s%s' % (str(num), binary) a = a / 2
import IPy >>>'192.168.1.100' in IPy.IP('192.168.1.0/24') is True >>>'192.168.1.0/24' in IPy.IP('192.168.0.0/16') is True >>>'192.168.1.0/24' in IPy.IP('192.168.0.0-192.168.8.255') is True 参考链接: https://blog.csdn.net/qq_41663245
python匹配ip正则 #!/usr/bin/env python # -*- coding:utf-8 -*- import re ip_str = "asdad1.1.1.1sdfwe2.6.5.7sdfsf2.3.94.5sdf200.198.25.0" res = [] for i in range(1): ip_t = True m_ind = 0 while ip_t: m = re.search(r"(((2([0-4]\d|5[0-5])|((1\d|[1-