Skip to main content

NgrokLinkify

A tool to expose your Ngrok URLs in an easy-to-access way. This tool uses the Ngrok free plan to get public URLs for your internal services and expose them. You can either use a telegram bot to get the public URLs or use redirection on Github pages to get a permanent URL to access your tunnels.

  • Expose your tunnels public URL conveniently for your friends
  • No need for setting up port forwarding on your system
  • Relatively safe, no hardening needed
  • Two choices to expose URLs: Telegram bot and Github pages
  • Setup as a systemd service to do this on boot

Related Libraries

Installation

Dependencies

  1. You'll have to install Ngrok by downloading it from here. For ease of use you can create a config file similar to the one below
authtoken: TOKEN_ID 
region: in # Set the region to closest one from your location
log_level: info
log_format: json
log: /var/log/ngrok.log
tunnels:
        jupyter: # Name of the tunnel
                proto: http
                addr: 1234 # Port number of the service
                bind_tls: true
        file-download:
                proto: http
                addr: 5678
                bind_tls: true
        heimdall:
                proto: http
                addr: 1111
                bind_tls: true

The name of your tunnel will be the path to the redirect link on Github pages. For ex. to visit the jupyter service you need to visit https://<github-username>.github.io/jupyter. You'll be redirected to the tunnel and should be able access your service.

  1. You'll also need to install these dependencies
pip install PyGithub python-telegram-bot

Install NgrokLinkify

pip install NgrokLinkify

Once you install the tool you'll need to create a config file. The basic structure of the config file is available in the package as example-cfg.ini. You can copy the file and edit it according to your system.

[Default]
NgrokUrl = http://127.0.0.1:4040/api/tunnels #API endpoint for Ngrok, this is the default value
LogFile = /var/log/NgrokLinkify.log #Location of the Log File
[Git]
RepoPath = /path/to/github-pages/repo #Change this to the path to your local git pages repo
CommitComment = Committed URL at {0} # Commit Message when committing Github Pages
PagesContent = ---\ntitle: {0}\nredirect_to: {1}\n---\n #The content of the redirect file, I use https://github.com/jekyll/jekyll-redirect-from. You can use raw HTML by following https://stackoverflow.com/questions/5411538/redirect-from-an-html-page and replacing the URL by {0} 
[Telegram]
FailureMsg = The server is not running currently! Ping @username #The Failure message to return when Ngrok isn't running
SuccessMsg = The public urls are \n ---------------------- \n{0} #The success message, {0} here contains tunnel name and public url
BotToken = 123123123 #The Bot token for telegram bot

Setup github repo

To ensure that you can update githuba pages without entering username or password. Enable ssh login to github by following this guide. Once done create and pull your github pages repo to the location mentioned in the config file.

Once you've enabled ssh access to your repo, set the upstream branch with ssh using the following command in the repo directory. Note the URL has to be a ssh url.

git remote set-url origin git@github.com:bagdeabhishek/bagdeabhishek.github.io.git 

Usage

You can directly run the utility by using linkify command

Simple command line usage

linkify -config /path/to/config/file

You can choose to enable telegram bot or update the github page with redirection. use the -h flag to get help

Use it programmatically inside python script

from NgrokLinkify.linkify import Linkify 
Linkify(start_telegram_bot=False ,update_github_pages=True,config_file="/home/abhishek/linkify.ini")

Options

The command line utility accepts the following arguments

--config CONFIG_FILE_LOCATION

Path to the configuration file

--exclude-telegram

Don't run telegram bot

--exclude-gh-pages

Do not update github pages

Persist the services using systemd

The package contains example service file for both NgrokLinkify and Ngrok. You can copy them to /etc/systemd/system/ location.

Ngrok systemd service file

[Unit]                                                                                                                  Description=Ngrok                                                                                                       After=network.service                                                                                                                                                                                                                           [Service]                                                                                                               Type=simple                                                                                                             User=user-name                                                                                                           WorkingDirectory=/home/abhishek                                                                                         ExecStart=/path/to/ngrok start --all --config=".ngrok2/ngrok.yml"                                       Restart=on-failure                                                                                                                                                                                                                              [Install]                                                                                                               WantedBy=multi-user.target 

Enable at boot

Create save this file as ngrok.service in /etc/systemd/system/ location. Run the following commands to enable Ngrok at boot

sudo systemctl daemon-reload;
sudo systemctl enable ngrok.service; 

NgrokLinkify systemd service

You can run NgrokLinkify as a service using the following example

[Unit]                                                                                                                  Description=Telegram bot to return URLs                                                                                 After=ngrok.service network.target network-online.target                                                                PartOf=ngrok.service                                                                                                                                                                                                                            [Service]                                                                                                               Type=simple                                                                                                             User=username                                                                                                           ExecStart=/home/username/miniconda3/bin/linkify --config /home/username/linkify.ini                Restart=on-failure                                                                                                                                                                                                                              [Install]                                                                                                               WantedBy=multi-user.target 

Save this file as NgrokLinkify.service in /etc/systemd/system/ location. Enable the service at boot using the follwing commands

sudo systemctl daemon-reload;
sudo systemctl enable ngrok.service; 

Metadata

Release files for NgrokLinkify 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for NgrokLinkify 1.0
File Size Uploaded
NgrokLinkify-1.0.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for NgrokLinkify 1.0
File Interpreter ABI Platform
NgrokLinkify-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / NgrokLinkify-1.0.tar.gz

Download URL NgrokLinkify-1.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
397d12f078ddbde9230379dfc3bf2cb0c567b4175a621b04bb0b84f3b507ea84
BLAKE2b-256 checksum
How to use checksums
755e6998c65b4807421af84d8a2294af55f4979cee0130eebd60fd2da2842868
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / NgrokLinkify-1.0-py3-none-any.whl

Download URL NgrokLinkify-1.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17560061d930fa5589c852663c8ab5f6b1d1ce8a929d921ae4a2ad7b77463c49
BLAKE2b-256 checksum
How to use checksums
3e41e014d07098dba1bd22dd8f22366e8a93bf909b9dfbe82eda14f0e962759e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page