Last active
December 27, 2020 07:25
-
-
Save Benau/705c231e3526aeb1306a24cb74b73d28 to your computer and use it in GitHub Desktop.
proton vpn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import urllib | |
import urllib.request | |
import ipaddress | |
import socket | |
import dns.resolver | |
# pip install dnspython | |
url_data = urllib.request.urlopen('https://api.protonmail.ch/vpn/logicals') | |
proton = json.loads(url_data.read().decode("utf-8")) | |
proton_ip = [] | |
for servers in proton['LogicalServers']: | |
for server in servers['Servers']: | |
entry_ip = int(ipaddress.ip_address(server['EntryIP'])) & 4294967040 # 255.255.255.0 | |
if not entry_ip in proton_ip: | |
proton_ip.append(entry_ip) | |
exit_ip = int(ipaddress.ip_address(server['ExitIP'])) & 4294967040 # 255.255.255.0 | |
if not exit_ip in proton_ip: | |
proton_ip.append(exit_ip) | |
proton_ip_asn = [] | |
for ip_24 in proton_ip: | |
ip_1 = (ip_24 >> 24) & 0xff | |
ip_2 = (ip_24 >> 16) & 0xff | |
ip_3 = (ip_24 >> 8) & 0xff | |
url = '0.' + str(ip_3) + '.' + str(ip_2) + '.' + str(ip_1) + '.origin.asn.cymru.com' | |
ips_asn = [] | |
for ans in dns.resolver.resolve(url, 'TXT'): | |
ip_asn = str(ans).split(' | ')[1] | |
ips_asn.append((ip_asn, ip_asn.split('/')[1])) | |
if not ips_asn: | |
continue | |
# Find the asn with the max /** to avoid too many hosts being included | |
ips_asn.sort(key=lambda tup: tup[1], reverse = True) | |
if not ips_asn[0][0] in proton_ip_asn: | |
proton_ip_asn.append(ips_asn[0][0]) | |
proton_ip_asn.sort() | |
for ip in proton_ip_asn: | |
print(ip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment