Sadiq is a user on You can follow them or interact with them if you have an account anywhere in the fediverse.

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)

it'll give me a chance to play with JSON data using Python

should be fun, I'll probably get started tomorrow

also if you open that API endpoint in Firefox, it gives you a nicely formatted view of the output

nice, that's cool

dealing with JSON seems fairly straightforward in Python 3

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

json, requests, dnspython (for interfacing with the Cymru IP-to-ASN thing - )

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 43 < list01 | sort -n > list02

also need socket I guess to resolve the instance hostnames into IPs


welcome to "Sadiq thinks out how he's going to write some code aloud on the TL"

I already have PyCharm installed but I should get a IPython[0] development environment going, that interactive shell is so good

[0] -

returns a list object

In [9]: type(r.json())
Out[9]: list

google pls stop returning python 2 documentation links thanks

Sadiq @staticsafe

friends don't let friends write Python 2 code in 2017

ยท Web ยท 27 ยท 42

@staticsafe we have users at work that still run Python 2.6 (because centos) and I despair every time

well in 2018 too and anytime in the future

say no to python 2

gaierror: [Errno -5] No address associated with hostname

dead instances, I need a way to clean the list I get from the API

@staticsafe catch the error and skip to the next item?

...: except:
...: print('ASN not found for IP: ' + z)
ASN not found for IP:

lmao some of the instances in the list I'm using have those A records

guess I should cleanup the iplist list more

another interesting one, the subnet is not being announced:

ASN not found for IP:

In [34]: asnlist.count(16276)
Out[34]: 199

199 in the list in AS16276 aka OVH

In [35]: asnlist.count(12876)
Out[35]: 138

138 in AS12876 aka

@staticsafe don't take this the wrong way but this conversation is making me very warm ๐Ÿ˜…

In [36]: asnlist.count(63949)
Out[36]: 71

71 in 63949 aka Linode

okay I think I've worked out a proof of concept inside IPython, time to actually write the script out

@staticsafe I will ๐Ÿ˜›. I donโ€™t want to port the whole legacy project to Python 3.

@thefishcrow my brain still stuck in 2017 apparently

@staticsafe i think a corollary of this is "don't let your friends use old CentOS versions in 2017"


unfortunately.... *cries quietly on the inside*

@staticsafe I started calling it python and legacy python.

@staticsafe they should have named it python++ to make it easy to Google *runs*

@Canageek @staticsafe uhh, i think that name has already been used ( for a binding generator or something, iirc? ) ๐Ÿคท

@Canageek @staticsafe pick a pack of CPickled,... wait is that still a thing in 3? iiiii forget.....