Created
January 24, 2018 20:30
-
-
Save espacioAntonio/6252c5c8237a6c5ebbb3b0dda48b941a to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import json | |
try: | |
# For Python 3.0 and later | |
from urllib.request import urlopen | |
except ImportError: | |
# Fall back to Python 2's urllib2 | |
from urllib2 import urlopen | |
def get_url(host="127.0.0.1", port="4040"): | |
try: | |
response = urlopen("http://" + host + ":" + port + "/api/tunnels/command_line") | |
data = response.read().decode("utf-8") | |
parsed = json.loads(data) | |
if 'public_url' in parsed: | |
return parsed['public_url'] | |
except Exception as e: | |
print(e) | |
return None | |
def get_host(): | |
url = get_url() | |
if url: | |
return url.split('://')[1] | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment