Client handling loss of connection
Today my ISP is having some issue causing repeated momentary loss of internet service.
On OSX 10.7, PIA client v46 doesn't seem to notice loss of connection. Client needs to be disconnected then reconnected, or sometimes needs to be restarted after cycling Wifi.
On Windows with OpenVPN client it is more of a pain. The client will turn yellow but adapter status stays "connected", cannot reconnect or disconnect in client. So client needs to be closed, disable then reenable TAP adapter to initialise it, then open client and connect.
So I began looking into how I can automate these steps.
XP, using devcon to disable adaptor (netsh doesn't work).
To restart it:
A quick AutoHotkey script (tested):
Don't have to end openvpn.exe but I wanted to avoid the message box about failing to connect.
Windows 7 using WMIC:
https://answers.microsoft.com/en-us/windows/forum/windows_7-hardware/enabledisable-network-interface-via-command-line/17a21634-c5dd-4038-bc0a-d739209f5081
OSX, with Applescript (untested):
For some reason killall doesn't work:
On OSX 10.7, PIA client v46 doesn't seem to notice loss of connection. Client needs to be disconnected then reconnected, or sometimes needs to be restarted after cycling Wifi.
On Windows with OpenVPN client it is more of a pain. The client will turn yellow but adapter status stays "connected", cannot reconnect or disconnect in client. So client needs to be closed, disable then reenable TAP adapter to initialise it, then open client and connect.
So I began looking into how I can automate these steps.
XP, using devcon to disable adaptor (netsh doesn't work).
devcon status @root\net shows one TAP adapter, ID 0000
To restart it:
devcon restart @root\net\0000
A quick AutoHotkey script (tested):
#singleinstance force
; close openvpn process to avoid any messages
process, close, openvpn.exe
process, close, openvpn-gui.exe
; restart tap adapter (may be different on your system, run devcon first)
; location of devcon.exe may also need changing
run, %comspec% /c ""C:\Windows\devcon.exe" "restart" "@root\net\0000"",, hide
; start openvpn and connect
run, %comspec% /c ""C:\Program Files\OpenVPN\bin\openvpn-gui.exe" "--connect" "Netherlands.ovpn"",, hide
return
; close openvpn process to avoid any messages
process, close, openvpn.exe
process, close, openvpn-gui.exe
; restart tap adapter (may be different on your system, run devcon first)
; location of devcon.exe may also need changing
run, %comspec% /c ""C:\Windows\devcon.exe" "restart" "@root\net\0000"",, hide
; start openvpn and connect
run, %comspec% /c ""C:\Program Files\OpenVPN\bin\openvpn-gui.exe" "--connect" "Netherlands.ovpn"",, hide
return
Don't have to end openvpn.exe but I wanted to avoid the message box about failing to connect.
Windows 7 using WMIC:
https://answers.microsoft.com/en-us/windows/forum/windows_7-hardware/enabledisable-network-interface-via-command-line/17a21634-c5dd-4038-bc0a-d739209f5081
OSX, with Applescript (untested):
tell application "Private Internet Access"
quit
do shell script "networksetup -setairportpower en1 off"
do shell script "networksetup -setairportpower en1 on"
activate
end tell
set pia to "Private Internet Access"
-- trap error
try
-- trap error
try
do shell script "killall " & pia
end try
-- cycle wifi
end try
-- cycle wifi
do shell script "networksetup -setairportpower en1 off"
do shell script "networksetup -setairportpower en1 on"
do shell script "networksetup -setairportpower en1 on"
