Commit c7a9b35d authored by Tommy Lau's avatar Tommy Lau

Support mutli domain-name.txt

parent cbafb1e4
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import glob
import socket import socket
import xml.etree.ElementTree import xml.etree.ElementTree
import urllib2 import urllib2
...@@ -48,26 +50,28 @@ if __name__ == "__main__": ...@@ -48,26 +50,28 @@ if __name__ == "__main__":
addr, mask = l.split('=')[1].strip().split('/') addr, mask = l.split('=')[1].strip().split('/')
route_table[get_decimal_ip(addr)] = (addr, mask) route_table[get_decimal_ip(addr)] = (addr, mask)
with open("domains.txt", "r") as f: for fn in glob.glob("domain-*.txt"):
for line in f: print("Read from file [%s]" % fn)
domain = line.strip() with open(fn, "r") as f:
for line in f:
if len(domain) != 0 and domain[0] != '#': domain = line.strip()
print("Processing domain [%s] " % domain),
ip = socket.gethostbyname(domain) if len(domain) != 0 and domain[0] != '#':
print("IP: %s" % ip), print(" Processing domain [%s] " % domain),
decimal_ip = get_decimal_ip(ip) ip = socket.gethostbyname(domain)
exist = False print("IP: %s" % ip),
for t in route_table: decimal_ip = get_decimal_ip(ip)
if (get_decimal_ip(route_table[t][1]) & decimal_ip) == t: exist = False
exist = True for t in route_table:
break if (get_decimal_ip(route_table[t][1]) & decimal_ip) == t:
if exist: exist = True
print "exist, skip . . ." break
else: if exist:
addr, mask = query_cidr(ip) print "exist, skip . . ."
route_table[get_decimal_ip(addr)] = (addr, mask) else:
print("CIDR: %s/%s" % (addr, mask)) addr, mask = query_cidr(ip)
route_table[get_decimal_ip(addr)] = (addr, mask)
print("CIDR: %s/%s" % (addr, mask))
tables = sorted(route_table.items()) tables = sorted(route_table.items())
......
...@@ -3,6 +3,7 @@ route = 4.0.0.0/255.0.0.0 ...@@ -3,6 +3,7 @@ route = 4.0.0.0/255.0.0.0
route = 8.0.0.0/255.0.0.0 route = 8.0.0.0/255.0.0.0
route = 23.0.0.0/255.0.0.0 route = 23.0.0.0/255.0.0.0
route = 31.0.0.0/255.0.0.0 route = 31.0.0.0/255.0.0.0
route = 38.0.0.0/255.0.0.0
route = 46.4.0.0/255.255.0.0 route = 46.4.0.0/255.255.0.0
route = 54.0.0.0/255.0.0.0 route = 54.0.0.0/255.0.0.0
route = 62.0.0.0/255.0.0.0 route = 62.0.0.0/255.0.0.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment