I still run my custom local RIPE WHOIS service. This service allows me to perfor...
Harry Sintonen @harrysintonen@infosec.exchange
I still run my custom local RIPE WHOIS service. This service allows me to perform extremely fast WHOIS searches. I wrote this tool in early 2010 when I wanted to enrich logs with network name information, and understandably my IP address was quickly blocked by the online WHOIS service (it obviously was a bad idea to try run every IP address you saw through the server, it created a ton of whois queries and load to already taxed service, and getting blocked for it was justified).
The service has three parts:
1. Generating the network.db from RIPE DB dump.
2. Network service to allow queries to the data.
3. Tool that enriches any IP address in its input with the network name in brackets.
Generating the database:
- Fetch RIPE DB from ftp
- Parse and insert the data to SQLite database
curl ftp://ftp.ripe.net/ripe/dbase/split/ripe.db.inetnum.gz | gzip -cd | ./createnetworkdb.pl
Service:
- Load the whole database to memory, and serve it over localhost port. The internal search structure is a PATRICIA radix tree, but to conserve memory it uses 24-bit indices rather than pointers. The service consumes only 474MB memory when holding the whole RIPE DB (Note however, that not all WHOIS information is loaded to memory, only key parts).
- The super simplified API accepts socket connections and reads 4-byte input (IP address in network byte order) and returns JSON object with the WHOIS information.
- Implemented in C (mainly to allow precise control over data structures and thus memory consumption).
Tool:
- Python filter tool that matches IP addresses from stdin and performs query from the service. For each IP it replaces its IP with IP[networkname].
Bonus: The network.db SQLite database can be queried directly to extract other kinds of information out of it. For example, searching IP ranges that match specific network name patterns has proven quite useful.
I'm sure many people have created something similar over the years. However, I had a lot of fun making this thing to be able to process tens of thousands of queries per second.