mirror of
https://github.com/notherealmarco/SLAACsense.git
synced 2025-05-05 20:32:34 +02:00
Normalize IP addresses before matching
This commit is contained in:
parent
d62a7ac9fb
commit
e405fdac2b
1 changed files with 4 additions and 4 deletions
8
main.py
8
main.py
|
@ -32,7 +32,7 @@ def get_dhcp4_leases():
|
||||||
def build_matches(ndp, leases):
|
def build_matches(ndp, leases):
|
||||||
matches = set()
|
matches = set()
|
||||||
for e in leases["rows"]:
|
for e in leases["rows"]:
|
||||||
ip6s = tuple(x["ip"].split("%")[0] for x in ndp["rows"] if x["mac"] == e["mac"] and e["if_descr"] == x["intf_description"])
|
ip6s = tuple(x["ip"].split("%")[0] for x in ndp["rows"] if x["mac"] == e["mac"])
|
||||||
if len(ip6s) == 0 and not DO_V4:
|
if len(ip6s) == 0 and not DO_V4:
|
||||||
continue
|
continue
|
||||||
matches.add((e["address"], ip6s, e["hostname"]))
|
matches.add((e["address"], ip6s, e["hostname"]))
|
||||||
|
@ -74,7 +74,7 @@ def sync_records(zones, match):
|
||||||
return
|
return
|
||||||
|
|
||||||
ip4 = match[0]
|
ip4 = match[0]
|
||||||
ip6s = [ipaddress.ip_address(x) for x in match[1]]
|
ip6s = [ipaddress.ip_address(x).compressed for x in match[1]]
|
||||||
hostname = match[2]
|
hostname = match[2]
|
||||||
|
|
||||||
if hostname == "":
|
if hostname == "":
|
||||||
|
@ -82,8 +82,8 @@ def sync_records(zones, match):
|
||||||
return
|
return
|
||||||
|
|
||||||
existing_records = get_existing_records(hostname, zone)
|
existing_records = get_existing_records(hostname, zone)
|
||||||
existing_ips = {r["rData"]["ipAddress"] for r in existing_records if r["type"] in ["A", "AAAA"]}
|
existing_ips = {ipaddress.ip_address(r["rData"]["ipAddress"]).compressed for r in existing_records if r["type"] in ["A", "AAAA"]}
|
||||||
current_ips = set([ip4] if DO_V4 else []) | {ip.exploded for ip in ip6s}
|
current_ips = set([ipaddress.ip_address(ip4).compressed] if DO_V4 else []) | set(ip6s)
|
||||||
|
|
||||||
# Delete outdated records
|
# Delete outdated records
|
||||||
for ip in existing_ips - current_ips:
|
for ip in existing_ips - current_ips:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue