aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdtube/dtube.py48
1 files changed, 27 insertions, 21 deletions
diff --git a/dtube/dtube.py b/dtube/dtube.py
index 80ca57d..7261ef5 100755
--- a/dtube/dtube.py
+++ b/dtube/dtube.py
@@ -74,6 +74,25 @@ class He:
return HeCountry(match.group(1), verbose=verbose)
raise Exception("Unable to identify target as AS / IPrange / IP / DNS / Country")
+ @classmethod
+ def parse_AS_announces_table(cls, table_it):
+ as_it = table_it.xpath('tbody/tr')
+ AS = dict()
+ if as_it:
+ for a in as_it:
+ AS[a.xpath('td[position()=1]/a/child::text()')[0]] = {
+ "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]
+ }
+ AS_txt = ""
+ if len(AS.keys()) > 0:
+ for a in AS:
+ AS_txt += a + '\t' + AS[a]["IPrange"] \
+ + '\t' + AS[a]["description"] + '\n'
+ return AS, AS_txt
+
def __init__(self, url, fromfile=None, verbose=False):
self.url = url
self.verbose = verbose
@@ -147,8 +166,8 @@ class HeIPrange(He):
def parse(self):
# Network Info
- info_it = self.tree.xpath('//div[@id="netinfo"]')[0]
- self.info = [e.text for e in info_it.getiterator()] # XXX ugly
+ info_it = self.tree.xpath('//div[@id="netinfo"]/table')[0]
+ (self.AS, self.AS_txt) = He.parse_AS_announces_table(info_it)
# XXX Whois
# DNS
dns_l = self.tree.xpath('//div[@id="dns"]')
@@ -172,10 +191,11 @@ class HeIPrange(He):
# XXX IRR
def show(self):
- print "====== INFO ======"
- print self.info
+ print "====== AS ======"
+ print "AS\tIPrange\t\tDescription"
+ print self.AS_txt
print "====== DNS ======"
- print "IP\tPTR [| A]"
+ print "IP\t\tPTR\t[| A]"
print self.dns_txt
class HeIP(He):
@@ -189,22 +209,8 @@ class HeIP(He):
def parse(self):
# IP Info
- info_it = self.tree.xpath('//div[@id="ipinfo"]')[0]
- as_it = info_it.xpath('table/tbody/tr')
- self.AS = dict()
- if as_it:
- for a in as_it:
- self.AS[a.xpath('td[position()=1]/a/child::text()')[0]] = {
- "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]
- }
- self.AS_txt = ""
- if len(self.AS.keys()) > 0:
- for a in self.AS:
- self.AS_txt += a + '\t' + self.AS[a]["IPrange"] \
- + '\t' + self.AS[a]["description"] + '\n'
+ info_it = self.tree.xpath('//div[@id="ipinfo"]/table')[0]
+ (self.AS, self.AS_txt) = He.parse_AS_announces_table(info_it)
# XXX Whois
# DNS
dns_it = self.tree.xpath('//div[@id="dns"]')[0]