snarl.de

Sadiq Mastodon
now that Mastodon has api/v1/instance/peers I want to write a script to do some analysis of what autonomous systems Mastodon instances are distributed across

Cymru provides a IP -> ASN lookup service so I could use that

(at least from this instance's perspective)
Sadiq Mastodon
it'll give me a chance to play with JSON data using Python

should be fun, I'll probably get started tomorrow
Sadiq Mastodon
also if you open that API endpoint in Firefox, it gives you a nicely formatted view of the output

nice, that's cool
Sadiq Mastodon
dealing with JSON seems fairly straightforward in Python 3

https://docs.python.org/3/library/json.html

so I reckon I'm gonna need the following imports:

json, requests, dnspython (for interfacing with the Cymru IP-to-ASN thing - http://www.team-cymru.org/IP-ASN-mapping.html )

19.2. json — JSON encoder and decoder — Python 3.6.4 documentation

19.2. json — JSON encoder and decoder — Python 3.6.4 documentation
Sadiq Mastodon
actually doesn't look like I need dnspython, I can use GNU netcat to feed a file of IPs to the Cymru WHOIS server

$ netcat whois.cymru.com 43 < list01 | sort -n > list02
Sadiq Mastodon
also need socket I guess to resolve the instance hostnames into IPs

socket.getaddrinfo()
Sadiq Mastodon
welcome to "Sadiq thinks out how he's going to write some code aloud on the TL"
Sadiq Mastodon
I already have PyCharm installed but I should get a IPython [0]development environment going, that interactive shell is so good

[0]-

Jupyter and the future of IPython — IPython

Jupyter and the future of IPython — IPython
Sadiq Mastodon
requests has a built-in JSON decoder 😍

Quickstart — Requests 2.18.4 documentation

Quickstart — Requests 2.18.4 documentation
Sadiq Mastodon
returns a list object

In [9]: type(r.json())
Out[9]: list
Sadiq Mastodon
google pls stop returning python 2 documentation links thanks
Sadiq Mastodon
friends don't let friends write Python 2 code in 2017
Sadiq Mastodon
well in 2018 too and anytime in the future

say no to python 2
Sadiq Mastodon
gaierror: [Errno -5] No address associated with hostname

dead instances, I need a way to clean the list I get from the API
Eugen Mastodon
@staticsafe catch the error and skip to the next item?
Help us to cover the server costs for snarl.de
Click here to lend your support to: Help us to cover the server costs for snarl.de!