Hybrid Hacker

👾 Technical notes and hybrid geekeries

Automatically enable/disable L2TP on TPLink access point

  • Wed 09 January 2019
  • Code

As many expats (I'm Italian and I live in Berlin), I make extensive use of VPN to act as I was in my home country. There are tons of services out there (I personally use PrivateVPN), but that's not the topic of this post.

Unfortunately this kind of VPN services usually are not reliable enough to be always on in your home network. They get frequent disconnections, high latency, etc. For this reason it's a good idea to enable/disable them on demand. In my case I had a Fritzbox 7412 that doesn't really support L2TP and immediately after a TPLink Archer AC1200, a cheap Wifi router with VPN client capabilities. So far, so good.

The only issue with this router is that there's no API support and no remote access using terminal. The only option is the Web UI. That really sucks. Full of Javascript and Ajax. So how to automate L2TP vpn enable/disable action? Usually Urllib, Mechanize, Beautifulsoup are all good answers. But in this case with so much Javascript and Ajax they were not suitable. So I decided to use Selenium.

At work we use Selenium a lot for running functional tests, but I never used it for automation. Well I have to say that it's really powerful. I was able to automate everything in a flash with just a couple of lines of Python code.

You can find the result here.

Exactly after 2 day after building this script, I bought a new Mikrotik router switch that has API and much much better L2TP support 😁