I'm working on powershell dialer for calling after some steps a VPN tool.
One step is for the user, the selection of the device which is used for establish the connection. During this step I'm searching how I could test the VPN gateway, because if this test doesn't work, this mean that user could have a connection problem, like captive portal (if he try to connect from a hotel). So if this test failed, it's not neccessary to go further.
I have try with this :
$ip ="x.x.x.x"
if(Test-Connection -computername $ip -count 1 -quiet){
write-host "gateway is accessible"
}
The problem is : connection is OK and the VPN also (if I try connect), but I get no response from this script. Maybe It's not the correct way to test it.
Config : Win 7 / Powershell 4
I've found my solution with this post
By using this :
if(New-Object System.Net.Sockets.TCPClient -ArgumentList '$iSERVER','$PORT') {...}
It's working well.