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 (h UANGGR):
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.ap Pend (_ip.group ())
Extranet_ips = List (set (HUANGGR)-set (intranet_ips))
return intranet_ips,extranet_ips
I F __name__ = = ' __main__ ':
_legit_ip = []
_input = [' 10.12.16.224 ', ' 10.256.8.56 ', ' 192.168.257.1 ', ' 172.56.2 ' 5.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]) /pre>
Python determines legitimate IP and distinguishes between intranet and extranet addresses