Testing whether the VPN is running?

Adam Funk a24061 at ducksburg.com
Thu Feb 25 08:25:27 EST 2016


On 2016-02-23, Cameron Simpson wrote:

> On 18Feb2016 10:03, Adam Funk <a24061 at ducksburg.com> wrote:
>>On 2016-02-18, Ervin Hegedüs wrote:
>>> I think that the psutil modul could be better for you for this
>>> task:
>>> https://pypi.python.org/pypi/psutil/
>>>
>>> and see the "Network" section.
>>
>>if 'tun0' in psutil.net_if_addrs():
>>   # vpn is running
>>
>>Brilliant!  I've used psutil for something else, but I didn't know it
>>did that too.  My excuse is that the version on my system was 2.2.1,
>>which does not do that, so I installed the newer version with pip3.
>>Thanks for pointing me to that.
>
> You might also want to check that the interface is up.
>
> My personal hack (not for a VPN, but for "being online", which turns my ssh 
> tunnels on and off) is to look in the output of "netstat -rn" for a default 
> route. This may imply that an alternative test for you is to test for a route 
> to your VPN's address range?  Just an idea.

Also interesting to know, thanks.


-- 
Mrs CJ and I avoid clichés like the plague.



More information about the Python-list mailing list