|
@@ -483,12 +483,13 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
|
|
|
continue
|
|
|
|
|
|
item_isps = set()
|
|
|
+ ispblocks = {}
|
|
|
for ip in ips:
|
|
|
isp = "UNKNOWN"
|
|
|
+ ispblock = ip
|
|
|
if isinstance(ip, dict):
|
|
|
- #name_parts = ip['name'].split('-')
|
|
|
+ ispblock = ip['name']
|
|
|
desc_lines = ip['description'].split('\n')
|
|
|
- #isp = name_parts[0] + ' (' + desc_lines[0] + ')'
|
|
|
isp = desc_lines[0].strip()
|
|
|
|
|
|
# normalize name: strip company indication
|
|
@@ -504,6 +505,10 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
|
|
|
# normalize name: strip country suffixes (in Germany)
|
|
|
isp = re.sub(r'(DE|Deutschland|Germany|Nordrhein[- ]Westfalen|NRW|Baden[- ]Wuerttemburg|BW|Hessen|Niedersachsen|Rheinland[- ]Pfalz|RLP)$', '', isp, flags=re.IGNORECASE).strip()
|
|
|
|
|
|
+ if not isp in ispblocks:
|
|
|
+ ispblocks[isp] = set()
|
|
|
+ ispblocks[isp].add(ispblock)
|
|
|
+
|
|
|
item_isps.add(isp)
|
|
|
|
|
|
if len(item_isps) == 0:
|
|
@@ -531,17 +536,22 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
|
|
|
elif outputformat == 'json':
|
|
|
self.send_headers('text/json')
|
|
|
|
|
|
- data = [ { 'name': x, 'count': isps[x], 'percentage': isps[x]*100.0/isps_sum } for x in isps ]
|
|
|
+ data = [ { 'name': isp, 'count': isps[isp], 'percentage': isps[isp]*100.0/isps_sum, 'blocks': [block for block in ispblocks[isp]] } for isp in isps ]
|
|
|
self.wfile.write(json.dumps(data))
|
|
|
|
|
|
elif outputformat == 'html':
|
|
|
self.send_headers()
|
|
|
|
|
|
self.wfile.write('<!DOCTYPE html><html><head><title>BATCAVE - PROVIDERS</title></head><body>\n')
|
|
|
- self.wfile.write('<table border="2"><thead><tr><th>Count</th><th>Percentage</th><th>Name</th></tr></thead><tbody>\n')
|
|
|
+ self.wfile.write('<table border="2"><thead><tr><th>Count</th><th>Percentage</th><th>Name</th><th>Blocks</th></tr></thead><tbody>\n')
|
|
|
|
|
|
for isp in sorted(isps, key=lambda x: isps[x], reverse=True):
|
|
|
- self.wfile.write('<tr><td>{0}</td><td>{1:.1f}%</td><td>{2}</td></tr>\n'.format(isps[isp], isps[isp]*100.0/isps_sum, isp))
|
|
|
+ self.wfile.write('<tr><td>{0}</td><td>{1:.1f}%</td><td>{2}</td><td>{3}</td></tr>\n'.format(
|
|
|
+ isps[isp],
|
|
|
+ isps[isp]*100.0/isps_sum,
|
|
|
+ isp,
|
|
|
+ ', '.join(sorted(ispblocks[isp])),
|
|
|
+ ))
|
|
|
|
|
|
self.wfile.write('</tbody></table>\n')
|
|
|
self.wfile.write('<p>Totals: {0} ISPs, {1} connections</p>\n'.format(len(isps), isps_sum))
|