From 58047ba09c47afe262ecabb6828946161004ce00 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 3 Feb 2023 17:23:24 -0700 Subject: run v4/v6 whois sockets on unique threads --- README | 24 ++++++++++++++---------- asn.py | 11 ++++++----- 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', -- cgit v1.2.3-54-g00ecf