Skip to content

Instantly share code, notes, and snippets.

@Dalimil
Created March 10, 2017 13:52
Show Gist options
  • Save Dalimil/408acef183cc9d19bd066829d234a91e to your computer and use it in GitHub Desktop.
Save Dalimil/408acef183cc9d19bd066829d234a91e to your computer and use it in GitHub Desktop.
Get ngrok URL from command line
# ngrok should be running
# replace http with https at the end if needed
# based on: https://gist.github.com/rjz/af40158c529d7c407420fc0de490758b
echo $(curl -s localhost:4040/inspect/http | grep -oP 'window.common[^;]+' | sed 's/^[^\(]*("//' | sed 's/")\s*$//' | sed 's/\\"/"/g') | jq -r ".Session.Tunnels | values | map(.URL) | .[]" | grep "^http:"
@Da-Real-Kryall
Copy link

doesn't seem to work with tcp tunnels

@Dashbloxx
Copy link

i think you need to remove "http:" at the end with "tcp:"

doesn't seem to work with tcp tunnels

@waitem
Copy link

waitem commented Jun 11, 2023

An alternative is to use the ngrok api. see: ngrok agent api - tunnel detail

Pipe the output to jq to extract the appropriate value. e.g. to extract the public_url of my https tunnel I run:

curl -s http://localhost:4040/api/tunnels | jq ".tunnels[0].public_url"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment