aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2023-02-03 17:23:24 -0700
committerJordan <me@jordan.im>2023-02-03 17:23:24 -0700
commit58047ba09c47afe262ecabb6828946161004ce00 (patch)
tree451a8d242b7be74f7feed56e097ee7b26ed2eb3a
parentb1d2547c09c788d551b052447fc49e9c12b642be (diff)
downloadasn-dualstack-support.tar.gz
asn-dualstack-support.zip
run v4/v6 whois sockets on unique threadsdualstack-support
-rw-r--r--README24
-rwxr-xr-xasn.py11
2 files changed, 20 insertions, 15 deletions
diff --git a/README b/README
index cd58d79..c85782e 100644
--- a/README
+++ b/README
@@ -1,18 +1,22 @@
asn: map hosts to their corresponding ASN via HTTP/WHOIS
-usage: asn.py [-h] [--whois-host WHOIS_HOST] [--whois-port WHOIS_PORT] [--http-host HTTP_HOST]
- [--http-port HTTP_PORT] [--update] [--populate]
+usage: asn.py [-h] [--bind-whois-v4 WHOIS_V4] [--bind-whois-v6 WHOIS_V6] [--bind-whois-port WHOIS_PORT]
+ [--bind-http-v4 HTTP_V4] [--bind-http-v6 HTTP_V6] [--bind-http-port HTTP_PORT] [--update] [--populate]
options:
-h, --help show this help message and exit
- --whois-host WHOIS_HOST
- IP to listen on for WHOIS service (default: 127.0.0.1)
- --whois-port WHOIS_PORT
- Port to listen on for WHOIS service (default: 4343)
- --http-host HTTP_HOST
- IP to listen on for HTTP service (default: 127.0.0.1)
- --http-port HTTP_PORT
- Port to listen on for HTTP service (default: 8080)
+ --bind-whois-v4 WHOIS_V4
+ WHOIS IPv4 host (default: 127.0.0.1)
+ --bind-whois-v6 WHOIS_V6
+ WHOIS IPv6 host (default: ::1)
+ --bind-whois-port WHOIS_PORT
+ WHOIS port (default: 4343)
+ --bind-http-v4 HTTP_V4
+ HTTP IPv4 host (default: 127.0.0.1)
+ --bind-http-v6 HTTP_V6
+ HTTP IPv6 host (default: ::1)
+ --bind-http-port HTTP_PORT
+ HTTP port (default: 8080)
--update Update dataset submodule and create/populate cache (default: False)
--populate Create and populate cache from current dataset (default: False)
diff --git a/asn.py b/asn.py
index eca0524..cec4017 100755
--- a/asn.py
+++ b/asn.py
@@ -121,9 +121,11 @@ class WHOISListener(Common):
Common.__init__(self)
self.db = db
if v4:
- self._listen_v4(v4, port)
+ listen_v4 = Thread(target=self._listen_v4, args=(v4, port))
+ listen_v4.start()
if v6:
- self._listen_v6(v6, port)
+ listen_v6 = Thread(target=self._listen_v6, args=(v6, port))
+ listen_v6.start()
def _listen_v4(self, host, port):
with socket.socket() as _socket:
@@ -136,8 +138,7 @@ class WHOISListener(Common):
args=(conn,addr,), daemon=True).start()
def _listen_v6(self, host, port):
- with (socket.socket(socket.AF_INET6, socket.SOCK_DGRAM,
- socket.IPPROTO_UDP) as _socket):
+ with socket.socket(family=socket.AF_INET6) as _socket:
_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
_socket.bind((host, port))
_socket.listen()
@@ -324,7 +325,7 @@ class DB:
break
if __name__ == '__main__':
- desc = 'asn: map hosts to their corresponding ASN via WHOIS'
+ desc = 'asn: map hosts to their corresponding ASN via HTTP/WHOIS'
parser = argparse.ArgumentParser(description=desc,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--bind-whois-v4', dest='whois_v4', type=str, action='store',