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.
The following code snippet shows a default setup for a Flask server in python. It listens on the defined IP address and port.
1##!/usr/bin/env python3 2from flask import Flask 3import os 4 5app = Flask(__name__) 6 7if __name__ == '__main__': 8 app.run(host="192.168.42.19", port=5000)
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
1def enableVPNRoute(): 2 print("enable VPN") 3 os.system("ip rule add iif enp3s0 lookup 51820") 4 os.system("ip rule flush") 5 pass 6 7 8def disableVPNRoute(): 9 print("disable VPN") 10 os.system("ip rule del iif enp3s0 lookup 51820") 11 pass 12 13 14def isVPNOn(): 15 ir = os.popen("ip rule").read() 16 return "iif" in ir
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
Establishing the Routes
firstname.lastname@example.org('/amazon') 2def amazon(): 3 if not isVPNOn(): 4 enableVPNRoute() 5 return "Turned VPN on. Enjoy Amazon :-)" 6 7 email@example.com('/netflix') 9def netflix(): 10 if isVPNOn(): 11 disableVPNRoute() 12 return "Turned VPN off. Enjoy Netflix :-)" 13Enjoy your next movies and shows 😉