Table of Contents

D.IP

What is DIP

D.IP is the work of a couple of nights of work over the course of a couple
months. One of the reasons I have decided to work on it was so that I could see
more information about the places I get visits from. It is not terribly useful
to know, but I find it fun to look at ¯\(ツ)/¯. I also know that I could look
up the ASN and then find the ips
that are allocated to that number. I do not find that as fun to do though.

How It Works

The general idea on what is happening is I pull in the ranges and any extra information
for the range. I then insert this information into a postgres table with the extra
information as a json column. The key for the table is postgres’s builtin inet
type. This is the key to making the whole searching process take not as long as
some of the previous iterations I had written.

Platforms

Versions

Sqlite

This was the first and second fastest iteration. It worked by having individual
tables for each different platform. I would then load all the ranges into a global map after
a daily restart. The issue with the approach is that while it was fast the information
could be incorrect or out of date by the time a new request would come in. The other
issue with implementation is that there was a lot of manual intervention for deploying
and maintaining the database.

Redis

Once the sqlite version of D.IP stopped working because the database was accidentally
pruned I started working on the second version. This was the slowest version that
I have made. It would pull all the different ranges into redis with the key being
the range and the extra information as the value for that range. Then when searching
I would scan through all the ranges and parsed each range for every search. This
lead to very long search times with all 4 platforms taking a grand total of
9 seconds for a single search.

PostgreSQL

When talking to a friend about this issue he mentioned storing a start and stop range
for each range and using SQL to find the correct row. While looking to this more
I saw the builtin INET type for postgres and that you could check if an IP is in
the range with it. This was the best approach I have found so far and allows for easy
adding of new platforms as I find more official sources.

Things I Want to add

Most of the things I want to add besides more datacenters are improvements to
the frontend. The first would be adding some about modal or another way to show
the user how to use the frontend. The other major improvement would be mapping the
inputted IP’s onto a map so that their is another fun visualisation of the information.