Worth Exploring: bgpstuff.net

Darren O’Connor put together a BGP looking glass with web GUI. Nothing fancy so far… but he also offers REST API interface (because REST API sounds so much better than HTTP).

The REST API calls return text results, so you can use them straight in a Bash script. For example, here’s a simple script to print a bunch of details about your current IP address:

#!/bin/bash
IP=$(curl -s ifconfig.me)
echo Your public IP address: $IP
echo
curl https://bgpstuff.net/route?ip=$IP
curl https://bgpstuff.net/aspath?ip=$IP
curl https://bgpstuff.net/origin?ip=$IP

But of course we should frown on text printouts in the days of glorious JSON, and fortunately Darren thought about that and implemented JSON-formatted results (just add format=json to the URL). Combine that with jq and you could do almost anything without invoking the magic powers of Perl Regular Expressions, for example:

#!/bin/bash
IP=$(curl -s ifconfig.me)
ASN=$( curl -s "https://bgpstuff.net/origin?ip=$IP&format=json"|\ 
   jq '.originAsn')

Happy scripting ;)

Add comment
Sidebar