Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find a list of subdomains already in use with ngrok?

Tags:

ngrok

We are using ngrok in our CI build in order to test an API using a third party service. This has proven quite successful, except supporting concurrent builds seems to be a lot more difficult.

In order to support concurrency, we decided to get reserved domains, lets say:

  • custom-domain
  • custom-domain2
  • custom-domain3

I wrote a script to check for available domains, and use the first one it finds that is available. The script is crude, and relies on ngrok terminating when we try to use a subdomain already in use:

#!/bin/bash

wget https://dl.ngrok.com/ngrok_2.0.19_linux_amd64.zip
unzip ngrok_2.0.19_linux_amd64.zip
./ngrok authtoken <account_token>
./ngrok http -subdomain=custom-domain 5000 &
sleep 5
curl http://localhost:4040/status
if [[ $? -eq 0 ]]
then
  export HOST=custom-domain.ngrok.io
else
  ./ngrok http -subdomain=custom-domain2 5000 &
  sleep 5
  curl http://localhost:4040/status
  if [[ $? -eq 0 ]]
  then
    export HOST=custom-domain2.ngrok.io
  else
    ./ngrok http -subdomain=custom-domain3 5000 &
    sleep 5
    curl http://localhost:4040/status
    if [[ $? -eq 0 ]]
    then
      export HOST=custom-domain3.ngrok.io
    else
      exit 1
    fi
  fi
fi

I tried refactoring this to use the client API, but the client API only looks at localhost, it is not aware of subdomains in use elsewhere on the internet. What I'm looking for does seem to be possible, as the ngrok.io website itself does list the subdomains in use at the moment, I just need to figure out how they are doing that? I'm using version 2.0.

With the script method, it does seem to work when using custom-domain but when using 2 or 3, we seem to get errors when POSTing to the endpoint, with the only suspicious thing in the logs being:

(some numbers changed)

t=2015-12-21T16:03:17+0000 lvl=warn msg="failed to open private leg" id=094b633d8754 privaddr=localhost:4567 err="dial tcp 127.0.0.1:4567: connection refused"

like image 283
Abe Petrillo Avatar asked Dec 03 '25 22:12

Abe Petrillo


1 Answers

ngrok's REST API has an endpoint for listing all online tunnels.

List all online tunnels currently running on the account.

like image 136
user2738058 Avatar answered Dec 08 '25 11:12

user2738058



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!