aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2022-07-24 09:40:07 -0700
committerJordan <me@jordan.im>2022-07-24 09:40:07 -0700
commit9f7cecdb131f7295e315bc9ea6c829025b773188 (patch)
tree8b85d29b90ad88fb09371bf83902fb4ff2755aab
parent3755e1047db0b9ffdd7b8e0ea54d5e2ef3683fb7 (diff)
downloadasn-9f7cecdb131f7295e315bc9ea6c829025b773188.tar.gz
asn-9f7cecdb131f7295e315bc9ea6c829025b773188.zip
asn: return A/AAAA record(s) in reply
-rw-r--r--README14
-rwxr-xr-xasn.py23
m---------location-database0
3 files changed, 19 insertions, 18 deletions
diff --git a/README b/README
index 160d1c3..1224343 100644
--- a/README
+++ b/README
@@ -26,13 +26,13 @@ USAGE
$ whois -h whois.jordan.im 1.1.1.1
- AS Number | Country | AS Name | Announcement
- ----------+---------+---------------+-------------
- 13335 | AU | CLOUDFLARENET | 1.1.1.0/24
+ IP Address | AS Number | Country | AS Name | Announcement
+ -----------+-----------+---------+---------------+-------------
+ 1.1.1.1 | 13335 | AU | CLOUDFLARENET | 1.1.1.0/24
$ whois -h whois.jordan.im jordan.im
- AS Number | Country | AS Name | Announcement
- ----------+---------+-------------------+---------------
- 8943 | GB | Jump Networks Ltd | 185.73.44.0/22
- 8943 | GB | Jump Networks Ltd | 2001:ba8::/32
+ IP Address | AS Number | Country | AS Name | Announcement
+ ------------------+-----------+---------+-------------------+---------------
+ 185.73.44.145 | 8943 | GB | Jump Networks Ltd | 185.73.44.0/22
+ 2001:ba8:0:4031:: | 8943 | GB | Jump Networks Ltd | 2001:ba8::/32
diff --git a/asn.py b/asn.py
index f79ee6c..0eb8c6c 100755
--- a/asn.py
+++ b/asn.py
@@ -68,19 +68,24 @@ class Listener:
announcements = []
for host in hosts:
if self._is_invalid(host):
- return []
+ continue
n = self._get_netblock(host)
- if n:
- announcements.extend(self.db.query(n))
+ if not n:
+ continue
+
+ res = self.db.query(n)
+ if res:
+ res = list(res[0])
+ res.insert(0, str(host))
+ announcements.extend([res])
return announcements
def _pretty(self, announces):
- announces = sorted(announces, key=lambda x: ipaddress.ip_network(
- x[3]).version)
+ announces = sorted(announces, key=lambda x: ipaddress.ip_network(x[4]).version)
- head = ('AS Number', 'Country', 'AS Name', 'Announcement')
+ head = ('IP Address', 'AS Number', 'Country', 'AS Name', 'Announcement')
announces.insert(0, head)
w = [len(max(i, key=lambda x: len(str(x)))) for i in zip(*announces)]
@@ -229,7 +234,6 @@ class DB:
''', (kv.get('aut-num'), kv.get('net'), kv.get('country')))
def query(self, net):
- announcements = []
while True:
rows = self.con.execute('''
SELECT net.aut_num, net.country, asn.name, net.net
@@ -240,15 +244,12 @@ class DB:
WHERE net.net = ?
''', (str(net), str(net))).fetchall()
if len(rows) != 0:
- announcements.extend(rows)
- break
+ return rows
if net.prefixlen > 0:
net = net.supernet()
else:
break
- return announcements
-
if __name__ == '__main__':
desc = 'asn: map hosts to their corresponding ASN via WHOIS'
parser = argparse.ArgumentParser(description=desc)
diff --git a/location-database b/location-database
-Subproject 80cd5c76ee0c04960da618c18f2feaad2c1f5f0
+Subproject 07aa1203299d4e97d27b1faec65baf3535fe8f0