There are many reasons to connect python scripts to the internet. For one, it allows you to access data from a variety of sources. This can be extremely useful for data analysis and scientific research. Additionally, it allows you to interact with web services and APIs. This can be used to automate tasks or to build custom applications. Finally, connecting to the internet can allow you to share your scripts with others. This can be a great way to collaborate on projects or to simply show off your work.

NGROK is a free tool that can help you do that, it allows developers to expose a local development server to the public internet. It can be used for testing and demo purposes, or for providing a secure tunnel for remote access to a development server. NGROK is easy to use and requires no configuration. In this article, we’ll see how to you use NGROK in your own projects!

How does NGROK work?

NGROK is a handy tool that allows developers to tunnel their local host server to the internet. This means that you can test your web applications on your local machine, and then access them from anywhere in the world. ngrok is a reverse proxy that creates a secure tunnel to expose a local server behind a NAT or firewall to the internet. It aims to help application developers to test and debug their applications in a realistic production environment by providing a dynamic public URL to their development server.  It works for any internet-enabled application like Web, SOCKS5, and even Android/iOS applications.

Install and Setup NGROK

Installing and setting up NGROK is a simple process that only takes a few minutes. Follow the following steps to install NGROK:

  1. Head to the NGROK download page and grab the latest release for your platform. If you have downloaded the zip file, unzip the contents of the archive somewhere convenient and add the ngrok executable to your PATH.
  2. Then you’ll have to add an auth token to NGROK’s config and in order to get the auth token, you will have to create an account on NGROK’s website.
  3. After you are logged in, you can get your auth token on the Your Authtoken page; copy it from there and past it in the following command:
ngrok config add-authtoken <token>
  1. After your command is ready run in a command prompt or a terminal; if it runs successfully, then NGROK is installed on your system. You can confirm this by running a command or two: ngrok http 80 or ngrok help.

And we are done with the setup! We’ll now show you some examples of NGROK running on a Windows 10 computer.

Flask Example

To show you how you can use NGROK with servers, we have taken flask as an example; we’ll try to host the flask server on NGROK.

First let’s create a very simple flask application just enough for it to be able to start it’s server:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World'

if __name__ == '__main__':
    app.run()

If we run this script now, we would get a result like this:

Now, if we want to get this script online, we can run it through NGROK. To do that keep the local server running, open up a new command prompt or terminal and run the following command:

ngrok http <your localhost value>
Or this in our case
ngrok http 5000

Similarly, you can also start a TCP server instead of HTTP. You can do it by just changing HTTP to TCP in the command:

ngrok tcp <your localhost value>

This will start NGROK and you should see a result like this:

Here you can see, it gives you the link to where your local server is now hosted online! You can see it in the Forwarding section. Now you can try to open it up on your PC, phone, laptop, or anything that has a browser and you should get a result like this:

Let’s now discuss some of the other details about the result above. 

Session Status – the session status shows if you are online or offline; this may sound trivial but it is an important detail since (on at least the free plan) NGROK does have an 8-hour limit to it, you can’t just use it forever.

Latency – it shows how much of a delay there would be on a request, this will also increase if multiple users are interacting with the Forwarding link. 

Connections – these are metrics on your users, tll shows the number of users that are currently interacting with the generated link, opn is the currently open connections, and p50 / p90 is the 50th and 90th percentile round-trip request times.

By now you should have gotten the gist of it.

Final Words

 

In this article we’ve seen how NGROK can help you expose a local dev server to the world, giving you the ability to securely demo a project to a client. In addition, NGROK offers the ability to tunnel over HTTP or HTTPS, giving you the ability to securely access a local machine from the public internet. NGROK isn’t just a one-trick pony, it offers a lot of features.

That’s it for this blog, I hope it was helpful and that you learned a thing or two about NGROK. If you have any further questions about NGROK and how to use it, please don’t hesitate to ask in the comments. If you’d like to stay updated with the latest news about NGROK, please follow us on Twitter. Thanks for reading!