Sharefi — a hobby project (part 1/4)

Probhakar
4 min readApr 20, 2021

A mechanism to share personal wifi connection

Photo by Compare Fibre on Unsplash

I have a project idea where I want to sell my wifi 😛. Since most of the time I don’t stay at home, my wifi is underutilized. How can I sell it? It turns out that TPLink router has this capability of MAC filtering. So if someone wants to use my wifi for one day, I can “whitelist” his/her MAC address for 24 hours. After that I will remove it, so the person won’t be able to access it.

Here is the block diagram that I have in mind —

So the component I need to implement this is

  1. A server that will communicate with my TPLink router and will handle —
    a. User mobile number validation (I want a valid mobile number)
    b. Payment handling
    c. MAC address filtering
    d. Giving user necessary information (SSID, password) to connect to the router
  2. A schedular that will check for the expiry of a particular user and intern removing his/her MAC
  3. Since my ISP doesn’t provide a port forwarding feature, I can’t expose the server that I will create for 1 to the public. So I need some intermediator which will glue the end-user and the local server.

I have separated the task into 3 subtask

Task 1: I will develop the mechanism to expose my localhost/local server to the public

Task 2: I will develop the pages for user subscription and add a payment gateway for payment handling

Task 3: I will try to reverse-engineer the APIs that is required to communicate with the TPLink router via HTTP protocol since there is no such mechanism that exists

Task 4: I will create the schedular to keeps things tidy (restart a script if it dies, delete user is it expires etc.)

Today I will discuss Task 1

As I discussed already, my ISP doesn’t allow me for port forwarding, I need a mechanism to expose the local server to the public domain. After searching for a while I came to know about ngrok.

source: https://www.npmjs.com/package/ngrok

It is really awesome. Bit one downside is that for a free account, if I restart the endpoint changes, so I can give the endpoint to my customers. I need a static endpoint.

Guess what, Pythonanywhere or Heroku provides a static endpoint. So I created one Flask server and hosted it on Pythonanywhere. Whenever Ngork client restarts, it send the new endpoint to my Pythonanywhere server. My customer first visits the Pythonanywhere website, then the website dynamically redirects (see the below gif) to the ngork tunnel and in turn to my local server. How cool is that! Using this meta tag I am redirecting to ngork tunnel

<meta http-equiv=”refresh” content=”2; url=’{url}’” />
Python anywhere redirects the user to ngrok

This is how it works

pythonanywhere redirecting the user to ngrok endpoint
Actual Servers
node server and python wrapper of ngrok client

so the current status is

[] Task 1: I will develop the mechanism to expose my localhost/local server to the public

[⚠️] Task 2: I will develop the pages for user subscription and add a payment gateway for payment handling

[⚠️] Task 3: I will try to reverse-engineer the APIs that is required to communicate with the TPLink router via HTTP protocol since there is no such mechanism that exists

[⚠️] Task 4: I will create the schedular to keeps things tidy (restart a script if it dies, delete user if it expires etc.)

Here is a snap of some of the working APIs

setNgrokUrl API to set new ngrok url

I am maintaining the whole code in the single repo here

--

--