-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathngrok.py
More file actions
28 lines (23 loc) · 672 Bytes
/
ngrok.py
File metadata and controls
28 lines (23 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Module that gets the public Ngrok tunnel URLs by querying the local Ngrok API.
See https://ngrok.com/docs#client-api.
"""
import json
import urllib3
def get_public_urls():
"""Get a list of available external tunnel URLs"""
urls = []
try:
http = urllib3.PoolManager()
req = http.request('GET', 'http://localhost:4040/api/tunnels')
data = str(req.data, 'utf-8')
obj = json.loads(data)
tunnels = obj['tunnels']
for tunnel in tunnels:
urls.append(tunnel['public_url'])
except:
# Ngrok not running.
pass
return urls
if __name__ == '__main__':
print(get_public_urls())