Alle Knoten sind nun unter luebeck.freifunk.net erreichbar

Hi :smile:

Ich habe das script noch für python 2.7 portiert, ihr müsst nur via pip das module py2-ipaddress installieren.

#!/usr/bin/env python2
 
import json
import sys
import re
from ipaddress import *
from time import time
 
ValidHostnameRegex = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"
prefix = IPv6Network('2000::/3')
 
data = json.load(sys.stdin)
 
print """$TTL 600  ; 10 minutes
@     IN SOA  srv01.luebeck.freifunk.net. info.luebeck.freifunk.net. (
         %i ; serial
         600        ; refresh (10min)
         30         ; retry (30s)
         3600       ; expire (1 hour)
         60         ; minimum (1 minute)
         )
     NS srv01.luebeck.freifunk.net.
     """ % time()
 
HostnameRegex = re.compile(ValidHostnameRegex)
 
for i in data:
  node = data[i]
  try:
    hostname = node['hostname']
    if HostnameRegex.match(hostname) == None:
      continue
 
    address = None
 
    for a in node['network']['addresses']:
      a = IPv6Address(a)
      if a in prefix:
        address = a
        break
 
    if address:
      print "%s\tAAAA\t%s" % (hostname, address)
  except:
    pass

Und das cronjob script:

#!/bin/sh
export LC_ALL=en_US.UTF-8
alfred-json -zr 158 | /usr/bin/python script.py > /var/cache/bind/nodes.ffhl.zone
/usr/sbin/rndc reload

Have fun :wink:

1 „Gefällt mir“