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
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 )
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
also need socket I guess to resolve the instance hostnames into IPs
socket.getaddrinfo()
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] - http://ipython.org/
requests has a built-in JSON decoder 😍
http://docs.python-requests.org/en/master/user/quickstart/#json-response-content
returns a list object
In [9]: type(r.json())
Out[9]: list
friends don't let friends write Python 2 code in 2017
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?
@Gargron yep, trying a try/except atm
...: except:
...: print('ASN not found for IP: ' + z)
...:
ASN not found for IP: 127.0.0.1
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: 199.120.128.3
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 Online.net/Scaleway
@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.
@staticsafe but we are now in 3018
@staticsafe ::whispers:: *2018
@thefishcrow my brain still stuck in 2017 apparently
@staticsafe no worries!
@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 Is it OK if it's Python 6 (i.e. valid as Py2 and Py3)?
@staticsafe I started calling it python and legacy python.
@staticsafe Ya use
! ...../s
@Sir_Boops @staticsafe *stumbles in* what about RUST
@Isoleucine @staticsafe idk my skills in that are a bit rusty :p
@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? ) 🤷
@staticsafe @gdkar Pick another 🐍?
@Canageek @staticsafe pick a pack of CPickled,... wait is that still a thing in 3? iiiii forget.....
@staticsafe we have users at work that still run Python 2.6 (because centos) and I despair every time