Search code examples
pythonwifitethering

Detect if connected to the internet using a tethered phone in Python


I was wondering if there is a way to detect, from a python script, if the computer is connected to the internet using a tethered cell phone?

I have a Python script which runs a bunch of network measurement tests. Ideally, depending on the type of network the client is using (ethernet, wifi, LTE, ...) the tests should change. The challenge is how to get this information from the python client, with out asking the user to provide it. Especially detect tethering.


Solution

  • In case anyone is interested, what I ended up doing was keeping the phone connected to my machine and used ADB to get this info. The command I run is:

     adb shell dumpsys netstats
    

    This is also a useful link.