Skip to content

Instantly share code, notes, and snippets.

@espacioAntonio
Created January 24, 2018 20:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espacioAntonio/6252c5c8237a6c5ebbb3b0dda48b941a to your computer and use it in GitHub Desktop.
Save espacioAntonio/6252c5c8237a6c5ebbb3b0dda48b941a to your computer and use it in GitHub Desktop.
# -*- 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