DEV Community

Fernando Tricas García
Fernando Tricas García

Posted on

Please, allow me to control my router from a Python script

Somebody that looks at my github could think that I hate the web: I have done lot of work trying to avoid connecting to web pages. That's not the case, anyway: I love the web, but I'm not sure if I love opening a browser, starting a session, and using the mouse for very simple tasks. Anyway, I understand that the web is the standard interface (no more apps!) and I'm ok, as far as they let me interact with the webpages on my own way.

One thing that is sometimes interesting is to know which machines are connected to my home WiFi router: this needs to connect to the, login to a 'webpage' (remembering the password, or looking for it in you password manager), waiting, going to the adequate link, waiting, and looking in a quite inconvenient result for the expected connected devices.

I have the MitraStar GPT-2541GNAC
which my provider installed and this seems to be possible (with my previous provider we had a router with a 'web page' that used JavaScript intensively and it was more difficult). I found this project mitrastar reset and decided to give it a try.

My goal was not to reset the router but I found there the main steps needed to connect to the devide and start interacting so, this is the result: my mitrastar router project.
There we have the new option -l (based on networkmap.html URL) that:

  • Gets the URL content (with requests)
  • Processes the results (with BeautifulSoup; some day these devices will have an API).
  • Eliminates duplicates with a dictionary (dont't ask me why there are some duplicate IPs).
  • Shows then in the standard output.

Alt Text

As I don't like remembering passwords nor storing them in programs, I also have added the keyring module to store safely (I'm not sure about the level of this safety, it is just a matter of separating code from passwords). Some info about this in Storing credentials of your Python programs in the keyring.

Next steps? You know: I'll integrate this code as an ErrBot command and I'll be able to call them from anywhere I'll be in that moment.

Top comments (0)