import re def legit_ip(_ip): compile_ip = re.compile(‘^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$‘) if compile_ip.match(_ip): return True else: return False def ip_intr_extr(huanggr): intr = [10,172,192] intranet_ips = [] extranet_ips = [] for i in huanggr: for ii in intr: _ip = re.match( r‘%s.*‘ %(ii), i) if _ip: intranet_ips.append(_ip.group()) extranet_ips = list(set(huanggr)-set(intranet_ips)) return intranet_ips,extranet_ipsif __name__ == ‘__main__‘: _legit_ip = [] _input = [‘10.12.16.224‘, ‘10.256.8.56‘, ‘192.168.257.1‘, ‘172.56.25.2‘, ‘183.18.46.53‘, ‘86.17.46.12‘, ‘213.49.56.38‘] for _ip in _input: if legit_ip(_ip): _legit_ip.append(_ip) print(ip_intr_extr(_legit_ip)[0]) print(ip_intr_extr(_legit_ip)[1])
原文地址:https://www.cnblogs.com/hmysql/p/8904552.html
时间: 2024-10-17 09:24:16