Advertisement
timkofu

generate_bind9_conf

Aug 5th, 2014
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import os
  2. import ipaddr
  3.  
  4.  
  5. def sanitize_domains_and_ips():
  6.     raw_domains = os.path.join(os.path.dirname(__file__), 'master_blacklist')
  7.     domains = set()
  8.     ip_addresses = set()
  9.  
  10.     with open(raw_domains) as items:
  11.         for item in items.readlines():
  12.             item = item.strip().lower().strip('.')
  13.             try:
  14.                 if ipaddr.IPAddress(item):
  15.                     pass #ip_addresses.add(item)
  16.             except ValueError as e:
  17.                 domains.add(item)
  18.     return iter(domains) #, iter(ip_addresses)
  19.  
  20. def generate_bind9_conf(domains):
  21.     with open('/etc/bind/filter.conf','w') as conf:
  22.         for d in domains:
  23.             conf.write('zone "'+d+'" { type master ; file "/etc/bind/dummyblock"; }; \n')
  24.  
  25.  
  26. if __name__ == '__main__':
  27.     generate_bind9_conf(sanitize_domains_and_ips())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement