The Nextlevel Blog logo
  • About 
  • Research 
  • Tags 
  • Blog 
  1.   Blog
  1. Home
  2. Blog
  3. Easing VPN switching

Easing VPN switching

Posted on April 16, 2020 • 2 min read • 324 words
Networking   Programming  
Networking   Programming  
Share via
The Nextlevel Blog
Link copied to clipboard

On this page
Flask Server   Handling the VPN   Establishing the Routes  
Easing VPN switching

Following up to my entry about circumventing geoblocking, I’ve written a small python program solving my Netflix blocking problem.

I realized that Netflix is not working as they rigorously ban the use of VPNs or proxies. Hence, it does work when using my home server as gateway/router but not when I additionaly enable the VPN.

First, I tried to enable or disable the VPN when I see the corresponding DNS queries for either amazon or netflix services. However, it turned out that my TV communicates with each other service regardless of what I am currently using. Therefore it is not possible to identify the desired state.

To ease the trouble at least a bit, I wrote a small webserver which allows me to make the switch with the click on a bookmark.

Flask Server  

The following code snippet shows a default setup for a Flask server in python. It listens on the defined IP address and port.

Flask Server

##!/usr/bin/env python3
from flask import Flask
import os

app = Flask(__name__)

if __name__ == '__main__':
    app.run(host="192.168.42.19", port=5000)

Handling the VPN  

To handle the VPN switching I just remove or add the ip rules to forward the traffic either to my wireguard table or using the default one. A very hacky check routine identifies the current routing state.

Handling the VPN

def enableVPNRoute():
    print("enable VPN")
    os.system("ip rule add iif enp3s0 lookup 51820")
    os.system("ip rule flush")
    pass


def disableVPNRoute():
    print("disable VPN")
    os.system("ip rule del iif enp3s0 lookup 51820")
    pass


def isVPNOn():
    ir = os.popen("ip rule").read()
    return "iif" in ir

Establishing the Routes  

Finally, Flask introduces the app.route directives which I now use to enable the VPN if the webserver is called as http://192.168.42.19:5000/amazon or disabled as http://192.168.42.19:5000/netflix.

Establishing the Routes

@app.route('/amazon')
def amazon():
    if not isVPNOn():
        enableVPNRoute()
    return "Turned VPN on. Enjoy Amazon :-)"


@app.route('/netflix')
def netflix():
    if isVPNOn():
        disableVPNRoute()
    return "Turned VPN off. Enjoy Netflix :-)"
Enjoy your next movies and shows 😉
 Methods to Assess Cybersecurity Risks
Circumventing Amazon Geoblocking the Tech-Way 
On this page:
Flask Server   Handling the VPN   Establishing the Routes  
Nextlevel v/Peter Schneider

I work on everything cyber security and development, CVR: 42051993, mail: info@nextlevel-blog.de, phone: 60 59 76 35

Copyright © 2025 Peter Schneider. | Powered by Hinode.
The Nextlevel Blog
Code copied to clipboard