Sep-12-2022, 06:08 AM
(Sep-09-2022, 09:46 AM)DeaD_EyE Wrote:44.44.44.44.11
is not a Valid IP-Address. A valid IPv4Address consists of 4 blocks with numbers from 0 to 255.
The problem is, that you want to recognize IPv6Addresses to filter them out and accepting IPv4Addresses and treating invalid data as IPv4-Adrdresses?
from contextlib import suppress from ipaddress import IPv6Address, ip_address def make_ipv4_set(file_like): results = set() for line in map(str.strip, file_like): addr = None with suppress(ValueError): addr = ip_address(line) if isinstance(addr, IPv6Address): continue results.add(line) return results with ( open("ip1_file.txt") as ip1_file, open("ip2_file.txt") as ip2_file, ): ip1_set = make_ipv4_set(ip1_file) ip2_set = make_ipv4_set(ip2_file) results = ip1_set - ip2_set for ip in results: print(ip)Maybe I should take money for it....
Output:44.44.44.44.11 192.168.0.6 192.168.0.4 192.168.0.1 192.168.0.2
For some reason it doesn't work so I have send you the files which include File1 and File2.
The IP address present in File1 are still being displayed. File2 should compare the IP list and display which isn't in File1.