Filter ASN database based on multiple ASNs

Get the IP addresses of multiple ASNs from the IP to ASN (Free) and the ASN database (Premium)

asn_multiple_filtered_database (1)

If you want to create an AS-filtered database with a combination of multiple of ASes, follow the instructions below.

Step 1: Download the CSV format of your ASN database.

Here I am downloading the IP to ASN database.

curl -L<YOUR_TOKEN> -o asn.csv.gz

Step 2: Unzip the .gz database.

I am using the CLI utility gunzip, but you can use whatever compression software or tool you want to use.

gunzip asn.csv.gz

Step 3: Create a .txt file that contains the ASN you want to select

Create an asns.txt file that contains your desired ASNs. For example:


Step 4: Filter the IP database with the selected ASNs

Using grep like before, we will create the filtered database. However, we are going to use the -f option, which stands for “fixed strings” and pass our asns.txt file containing the selected ASNs.

(head -1 asn.csv;grep -f asns.txt asn.csv) > filtered_asns.csv


You can skip the uncompressing step and run grep on the compressed file with zgrep. Here I am running the grep on the compressed asn.csv.gz database and viewing it one less.

zgrep -f asns.txt asn.csv | less

IPinfo Database Downloads