Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103097 > unrolled thread
| Started by | Adam Funk <a24061@ducksburg.com> |
|---|---|
| First post | 2016-02-18 09:26 +0000 |
| Last post | 2016-02-25 15:01 -0800 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.lang.python
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
| From | Adam Funk <a24061@ducksburg.com> |
|---|---|
| Date | 2016-02-18 09:26 +0000 |
| Subject | Testing whether the VPN is running? |
| Message-ID | <2cfgpcxdg2.ln2@news.ducksburg.com> |
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? Thanks. -- Nam Sibbyllam quidem Cumis ego ipse oculis meis vidi in ampulla pendere, et cum illi pueri dicerent: beable beable beable; respondebat illa: doidy doidy doidy. --- plorkwort
[toc] | [next] | [standalone]
| From | Ervin Hegedüs <airween@gmail.com> |
|---|---|
| Date | 2016-02-18 10:45 +0100 |
| Message-ID | <mailman.240.1455788735.22075.python-list@python.org> |
| In reply to | #103097 |
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. Regards, a. -- I � UTF-8
[toc] | [prev] | [next] | [standalone]
| From | Adam Funk <a24061@ducksburg.com> |
|---|---|
| Date | 2016-02-18 10:03 +0000 |
| Message-ID | <8ghgpcxrd3.ln2@news.ducksburg.com> |
| In reply to | #103098 |
On 2016-02-18, Ervin Hegedüs 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. Oops, sorry! But your educated guess is right. :-) > 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. -- XML is like violence: if it doesn't solve the problem, use more.
[toc] | [prev] | [next] | [standalone]
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2016-02-23 19:24 +1100 |
| Message-ID | <mailman.62.1456215889.20994.python-list@python.org> |
| In reply to | #103102 |
On 18Feb2016 10:03, Adam Funk <a24061@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. Cheers, Cameron Simpson <cs@zip.com.au>
[toc] | [prev] | [next] | [standalone]
| From | Adam Funk <a24061@ducksburg.com> |
|---|---|
| Date | 2016-02-25 13:25 +0000 |
| Message-ID | <7vb3qcxocs.ln2@news.ducksburg.com> |
| In reply to | #103397 |
On 2016-02-23, Cameron Simpson wrote: > On 18Feb2016 10:03, Adam Funk <a24061@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.
[toc] | [prev] | [next] | [standalone]
| From | Gisle Vanem <gvanem@yahoo.no> |
|---|---|
| Date | 2016-02-23 10:40 +0100 |
| Message-ID | <mailman.65.1456220556.20994.python-list@python.org> |
| In reply to | #103102 |
Cameron Simpson: > 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. And for VPN in Windows *and* using WinPcap, one can check if this device exist: \Device\NPF_GenericDialupAdapter (controllable using 'sq query rasdial'). This works if you use PPTP or L2TP but not OpenVPN. BTW, a VPN on Windows doesn't come back up automatically after a sleep/hibernation. The WOSB tool at http://www.dennisbabkin.com/wosb/ could be handy. What happens with your VPN on Linux (?) after coming back from sleep/hibernation? Automatic or you need to script that too? -- --gv
[toc] | [prev] | [next] | [standalone]
| From | Dan Stromberg <drsalists@gmail.com> |
|---|---|
| Date | 2016-02-25 15:01 -0800 |
| Message-ID | <mailman.137.1456441753.20994.python-list@python.org> |
| In reply to | #103097 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web