diff --git a/mtprotoproxy.py b/mtprotoproxy.py index fa56ff1..0b308a7 100755 --- a/mtprotoproxy.py +++ b/mtprotoproxy.py @@ -3,6 +3,7 @@ import asyncio import socket import urllib.parse +import urllib.request import collections import time import hashlib @@ -226,17 +227,12 @@ async def stats_printer(): def print_tg_info(): - my_ip = socket.gethostbyname(socket.gethostname()) - - octets = [int(o) for o in my_ip.split(".")] - - ip_is_local = (len(octets) == 4 and ( - octets[0] in [127, 10] or - octets[0:2] == [192, 168] or - (octets[0] == 172 and 16 <= octets[1] <= 31))) - - if ip_is_local: - my_ip = "YOUR_IP" + try: + with urllib.request.urlopen('https://ifconfig.co/ip') as f: + if f.status != 200: raise Exception("Invalid status code") + my_ip = f.read().strip() + except: + my_ip = 'YOUR_IP' for user, secret in USERS.items(): params = {