Skip to content

Instantly share code, notes, and snippets.

@mlsteele
Created January 15, 2016 16:49
Show Gist options
  • Save mlsteele/f57adc1fab5c44656d6d to your computer and use it in GitHub Desktop.
Save mlsteele/f57adc1fab5c44656d6d to your computer and use it in GitHub Desktop.
Copy the url of the active ngrok connection to the clipboard.
#!/usr/bin/env bash
# Copy the url of the active ngrok connection to the clipboard.
# Usage:
# ngrok-copy # copies e.g. https://3cd67858.ngrok.io to clipboard.
# ngrok-copy -u # copies e.g. http://3cd67858.ngrok.io to clipboard.
if [[ "$1" == "-u" ]]; then
NGROK_URL=`curl -s http://127.0.0.1:4040/status | grep -P "http://.*?ngrok.io" -oh`
else
NGROK_URL=`curl -s http://127.0.0.1:4040/status | grep -P "https://.*?ngrok.io" -oh`
fi
if [[ $NGROK_URL != *"http"* ]]; then
echo "No url found. Is ngrok running?"
exit 1
fi
if [ "$(uname)" == "Darwin" ]; then
# OSX
echo $NGROK_URL | pbcopy
else
# Linux
echo $NGROK_URL | xclip -selection clipboard
fi
echo "Copied to clipboard: $NGROK_URL"
@varenc
Copy link

varenc commented Oct 25, 2019

ngrok no longer seems to report the url at http://127.0.0.1:4040/status. That info is now pulled in from an ajax call to http://127.0.0.1:4040/grpc/agent.Web/Preloaded.

Instead, ngrok has an API! This info is available at http://127.0.0.1:4040/api/tunnel now

I forked this gist and made a copy that works for me. Check it out! https://gist.github.com/varenc/6addfa03b03b318fe32612f67027bb1c

@FanchenBao
Copy link

Correction: the api endpoint is http://127.0.0.1:4040/api/tunnels ("tunnels" instead of "tunnel")

@mphomosia
Copy link

I have followed all instructions here but I get:

No url found. Is ngrok running?

@colemilne54
Copy link

@mphomosia You may be getting issues due to the /api/tunnels link as mentioned by @varenc and @FanchenBao

I found that along with that change, I had to tweak my port to 4043 and the url end to .ngrok-free.app.

I would look over your ngrok terminal display and note any differences like these that may require tweaking.

Here is my working version: https://gist.github.com/colemilne54/a2f4b3c6cd894ecd0dd0bf95b673aabb

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