aboutsummaryrefslogtreecommitdiffstats
path: root/dtube
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-03-10 00:33:26 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2013-03-10 00:33:26 +0100
commit53192e5961d82dba04dcbdbb322fb0c0a8be79b3 (patch)
tree32d518cc0297032974e57321551346b11692ea56 /dtube
parentdtube: handle IP DNS with empty PTR (diff)
downloadlaurent-tools-53192e5961d82dba04dcbdbb322fb0c0a8be79b3.tar.xz
laurent-tools-53192e5961d82dba04dcbdbb322fb0c0a8be79b3.zip
dtube: search for closest IPrange if not not found
Diffstat (limited to 'dtube')
-rwxr-xr-xdtube/dtube.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/dtube/dtube.py b/dtube/dtube.py
index 61ca79d..b0a868d 100755
--- a/dtube/dtube.py
+++ b/dtube/dtube.py
@@ -61,7 +61,20 @@ class He:
match = re.search(r'^([0-9]+(?:\.[0-9]+){3}/[0-9]+)$', target)
if match:
if verbose: print "Target identified as IPrange %s" % match.group(1)
- return HeIPrange(match.group(1), verbose=verbose)
+ try:
+ he = HeIPrange(match.group(1), verbose=verbose)
+ except Exception, e:
+ if str(e) == "Target not found":
+ print e
+ print "Trying to get closest range announcements"
+ ip = HeIP(match.group(1).split('/')[0], verbose=verbose)
+ as_target = max(ip.AS.iterkeys(), key=(lambda key: ip.AS[key]['position']))
+ iprange = ip.AS[as_target]["IPrange"]
+ print "New IPrange selected: %s" % iprange
+ he = HeIPrange(iprange, verbose=verbose)
+ else:
+ raise e
+ return he
match = re.search(r'^([0-9]+(?:\.[0-9]+){3})$', target)
if match:
if verbose: print "Target identified as IP %s" % match.group(1)
@@ -80,14 +93,17 @@ class He:
def parse_AS_announces_table(cls, table_it):
as_it = table_it.xpath('tbody/tr')
AS = dict()
+ position = 0
if as_it:
for a in as_it:
AS[a.xpath('td[position()=1]/a/child::text()')[0]] = {
+ "position": position,
"AS_href": a.xpath('td[position()=1]/a')[0].get('href'),
"IPrange": a.xpath('td[position()=2]/a/child::text()')[0],
"IPrange_href": a.xpath('td[position()=2]/a')[0].get('href'),
"description": a.xpath('td[position()=3]/child::text()')[0]
}
+ position += 1
AS_txt = ""
if len(AS.keys()) > 0:
for a in AS: