View random ngrok URL when run in background
If you want to get the first tunnel then jq
will be your friend:
curl -s localhost:4040/api/tunnels | jq -r .tunnels[0].public_url
When running more than one instance of ngrok then use the tunnel name /api/tunnels/:name
.
Run ./ngrok http & This runs the ngrok tunnel as a background process. Ngrok usually opens a window showing the assigned URL but since we are using the nohup command this is not visible.
Thus, then run curl http://127.0.0.1:4040/api/tunnels
too see the URL assigned by ngrok
This little Python (2.7) script will call the ngrok API and print the current URL's:
import json
import os
os.system("curl http://localhost:4040/api/tunnels > tunnels.json")
with open('tunnels.json') as data_file:
datajson = json.load(data_file)
msg = "ngrok URL's: \n'
for i in datajson['tunnels']:
msg = msg + i['public_url'] +'\n'
print (msg)
There are a couple of ways.
You can either:
1) Visit localhost:4040/status
in your browser to see a bunch of information, or
2) Use curl to hit the API: localhost:4040/api/tunnels