api/alfred: Mask public IPv6 addresses
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
a591554b3b
commit
c83c4eb860
|
@ -7,6 +7,8 @@ from ffmap.config import CONFIG
|
||||||
#from socket import inet_pton, inet_ntop, AF_INET6
|
#from socket import inet_pton, inet_ntop, AF_INET6
|
||||||
from ipaddress import IPv4Address, IPv6Address
|
from ipaddress import IPv4Address, IPv6Address
|
||||||
|
|
||||||
|
ipv6local = IPv6Address('fc00::')
|
||||||
|
|
||||||
def utcnow():
|
def utcnow():
|
||||||
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
|
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
|
||||||
|
|
||||||
|
@ -58,6 +60,20 @@ def ipv6tobin(data):
|
||||||
#return inet_pton(AF_INET6,data)
|
#return inet_pton(AF_INET6,data)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def ipv6tobinmasked(data):
|
||||||
|
if data:
|
||||||
|
ip = IPv6Address(data)
|
||||||
|
if ip >= ipv6local:
|
||||||
|
return ip.packed
|
||||||
|
else:
|
||||||
|
li = list(ip.packed)
|
||||||
|
# mask 1234:1234:ffff:ffff:ffff:ffff:ffff:ff34
|
||||||
|
li[4:15] = [255,255,255,255,255,255,255,255,255,255,255]
|
||||||
|
return IPv6Address(bytes(li)).packed
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def bintoipv6(data):
|
def bintoipv6(data):
|
||||||
if data:
|
if data:
|
||||||
return IPv6Address(data).compressed
|
return IPv6Address(data).compressed
|
||||||
|
|
|
@ -812,7 +812,7 @@ def parse_nodewatcher_xml(xml,statstime):
|
||||||
interface["ipv6_addrs"] = []
|
interface["ipv6_addrs"] = []
|
||||||
if len(netif.xpath("ipv6_addr/text()")) > 0:
|
if len(netif.xpath("ipv6_addr/text()")) > 0:
|
||||||
for ipv6_addr in netif.xpath("ipv6_addr/text()"):
|
for ipv6_addr in netif.xpath("ipv6_addr/text()"):
|
||||||
interface["ipv6_addrs"].append(ipv6tobin(ipv6_addr.split("/")[0]))
|
interface["ipv6_addrs"].append(ipv6tobinmasked(ipv6_addr.split("/")[0]))
|
||||||
|
|
||||||
router_update["netifs"].append(interface)
|
router_update["netifs"].append(interface)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue