In our previous post, we wrote about using PeeringDB to find information about potential peers, and then after peering has been arranged, using PeeringDB to obtain the peering details.
The PeeringDB website is very helpful in these regards, but using the website still requires a lot of manual work. It’s also possible to use the PeeringDB API to automate some parts of this. Today, we present an example script to obtain a list of potential peers from PeeringDB.
The PeeringDB database can be queried using a REST API. REST allows a client to request information from a server over HTTP or HTTPS. The server then returns the requested information in JSON format.
Our example script is written in PHP. PHP is mostly a web scripting language, but it can also be used on the command line. Our script uses the CURL, the Client URL Library, to perform HTTPS requests. On Linux/Unix systems installing PHP and the CURL library is usually quite easy, and on macOS they are installed by default. Please download the script below and save it with the extension .php:
Once downloaded, you can run the script as follows:
The script will then query PeeringDB to find out at which internet exchanges AS1200 is present. As AS1200 is the Autonomous System of AMS-IX, AS1200 is present at AMS-IX with two routers, so the script shows:
AMS-IX 1000 126.96.36.199 2001:7f8:1::a500:1200:1
AMS-IX 1000 188.8.131.52 2001:7f8:1::a500:1200:2
Total available bandwidth: 2 Gbps at 2 internet exchange locations.
(Obviously you’ll want to use your own AS number—you do have your AS registered with PeeringDB, don’t you?)
The next step is for the script to obtain a list of all networks present at the internet exchanges found above. These are the potential peers, and it’s usually a long list. This is the relatively modest output for Phyxia, AS35627:
AS35627 has a presence at:
FreeBIX 1000 184.108.40.206 2001:7f8:1b::3:5627:1
GN-IX 100 220.127.116.11 2001:7f8:31:0:5:3:5627:1Total available bandwidth: 1.1 Gbps at 2 internet exchange locations.
FreeBIX, Trance Nation, 34806, Open
FreeBIX, Connexeon, 35821, Open
FreeBIX, MAC Telecom, 50857, Open
FreeBIX, Netlog N.V., 41471, Open
FreeBIX, FR-NIC-DNS (AFNIC / NIC-France), 2484, Open
FreeBIX, HousingCenter, 28707, Open
FreeBIX, Hermes Telecom Group, 6824, Selective
GN-IX, De Kooi, 16318, Open
GN-IX, OpenPeering, 20562, Open
GN-IX, MetaMicro Automatisering BV, 41037, Open
GN-IX, Duocast BV, 31477, Open
GN-IX, CJ2 Hosting, 39704, Open
GN-IX, Plusine ICT, 198508, Open
GN-IX, gnTel, 41153, Open
The RS field indicates whether a network is connected to the route servers of the internet exchange, with 1 meaning yes and empty or 0 meaning no.
The script can also be run with the additional keyword csv, and then it will output a comma separated values file which can easily be imported into a database or spreadsheet. The output then looks like this:
“FreeBIX”,”Packet Clearing House”,”http://www.pch.net/”,3856,”1-5Gbps”,”Balanced”,”Global”,””,”Open”,”https://www.peeringdb.com/net/286″
“FreeBIX”,”Trance Nation”,”http://www.trancenation.be”,34806,”0-20 Mbps”,”Balanced”,”Europe”,”http://www.trancenation.be/?page=PeeringPolicy”,”Open”,”https://www.peeringdb.com/net/905″
This script should provide a simple example of how to interact with the PeeringDB API and it can provide a start for managing peering relationships. In our next blog post we’ll present a script that queries PeeringDB for AS numbers and IP addresses in order to generate router configurations to set up peering.