forked from emricht32/SquawkersMccaw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngrok_hostname.sh
executable file
·36 lines (30 loc) · 1.08 KB
/
ngrok_hostname.sh
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
29
30
31
32
33
34
35
36
# #!/bin/sh
# # ngrok's web interface is HTML, but configuration is bootstrapped as a JSON
# # string. We can hack out the forwarded hostname by extracting the next
# # `*.ngrok.io` string from the JSON
# #
# # Brittle as all get out--YMMV. If you're still reading, usage is:
# #
# # $ ./ngrok_hostname.sh <proto> <addr>
# #
# # To retrieve the ngrok'd URL of an HTTP service running locally on :3332, use:
# #
# # $ ./ngrok_hostname.sh http localhost:3332
# #
# # The protocol (http, https, etc) of the forwarded service
# PROTO=$1
# # The address of the forwarded service
# ADDR=$2
# # Hack JSON out of the web interface bootstrap
# json=$(curl -s localhost:4040/inspect/http \
# | ggrep -oP 'window.common[^;]+' \
# | sed 's/^[^\(]*("//' \
# | sed 's/")\s*$//' \
# | sed 's/\\"/"/g')
# # Parse JSON for the URLs matching the configured `$ADDR`
# hosts=$(echo $json \
# | jq -r ".Session.Tunnels \
# | values \
# | map(select(.Config.addr == \"$ADDR\") | .URL) | .[]")
# echo "$hosts" | ggrep "^${PROTO}:"
curl "localhost:4040/api/tunnels" | jq -r '.tunnels[1].public_url'