import requests def get_external_ip(): try: ip = requests.get("http://jsonip.com/").json().get('ip') return ip except: return None if __name__ =="__main__": ip = get_external_ip() print(ip)