Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103522

Re: Testing whether the VPN is running?

From Dan Stromberg <drsalists@gmail.com>
Newsgroups comp.lang.python
Subject Re: Testing whether the VPN is running?
Date 2016-02-25 15:01 -0800
Message-ID <mailman.137.1456441753.20994.python-list@python.org> (permalink)
References <2cfgpcxdg2.ln2@news.ducksburg.com> <20160218094531.GA5510@arxnet.hu>

Show all headers | View raw


On Thu, Feb 18, 2016 at 1:45 AM, Ervin Hegedüs <airween@gmail.com> wrote:
> Hi Adam,
>
> On Thu, Feb 18, 2016 at 09:26:58AM +0000, Adam Funk wrote:
>> I'd like to test (inside a python 3 program) whether the VPN is
>> running or not.  The only thing I can think of so far is to use
>> subprocess to run the 'ifconfig' command, then check its output for
>> 'tun0'.  Is there a better way?
>
> you didn't wrote, which system (OS) you want to use - based on
> the "ifconfig" and "tun0" keywords, possible that's a Linux.
>
> 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.

psutil is probably clean on Linux.

However, using the subprocess module to run ifconfig -a and check for
tun0 / utun0 should get you compatibility with both Linux and Mac.

Note that if I'm running a Linux in a VMware, and it's hosted on a
Mac, and the Mac has one of my VPN's up, then the Linux doesn't have a
tun0, but it can still see stuff only accessible via that VPN.

For that, it might be better to try ping'ing some host that's behind
the VPN.  In a way, that's a better test anyway.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Testing whether the VPN is running? Adam Funk <a24061@ducksburg.com> - 2016-02-18 09:26 +0000
  Re: Testing whether the VPN is running? Ervin Hegedüs <airween@gmail.com> - 2016-02-18 10:45 +0100
    Re: Testing whether the VPN is running? Adam Funk <a24061@ducksburg.com> - 2016-02-18 10:03 +0000
      Re: Testing whether the VPN is running? Cameron Simpson <cs@zip.com.au> - 2016-02-23 19:24 +1100
        Re: Testing whether the VPN is running? Adam Funk <a24061@ducksburg.com> - 2016-02-25 13:25 +0000
      Re: Testing whether the VPN is running? Gisle Vanem <gvanem@yahoo.no> - 2016-02-23 10:40 +0100
  Re: Testing whether the VPN is running? Dan Stromberg <drsalists@gmail.com> - 2016-02-25 15:01 -0800

csiph-web