Solved

check for cisco vpn connection...enabled or disabled

Posted on 2013-12-05
4
613 Views
Last Modified: 2014-01-09
I have a CISCO Vpn anyconnect secure mobility client.
v 3.1.02040

Does any one know of a way in vba to check and see if a vpn connection is established or not ?


Thanks
fordraiders
0
Comment
Question by:fordraiders
  • 3
4 Comments
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 39700170
You can ping far side of vpn connection. Details of WMI Win32_PingStatus you can find here:
http://msdn.microsoft.com/library/aa394350(v=VS.85).aspx
Vba version:
Sub test()
If Ping("192.168.2.2") Then
    MsgBox "Passed", vbOKOnly
Else
    MsgBox "Failed", vbOKOnly
End If
End Sub
Public Function Ping(ByVal ComputerIP As String) As Boolean
    'You can use also name of computer
    ' Return TRUE, if pin was successful
   Dim oPingResult As Variant
    For Each oPingResult In GetObject("winmgmts://./root/cimv2").ExecQuery _
        ("SELECT * FROM Win32_PingStatus WHERE Address = '" & ComputerName & "'")
        If IsObject(oPingResult) Then
            If oPingResult.StatusCode = 0 Then
                Ping = True
                'Debug.Print "ResponseTime", oPingResult.ResponseTime 'You can also return ping time
               Exit Function
            End If
        End If
    Next
End Function

Open in new window

0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39712241
Thanks !
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39769586
als315, This is passing any test i give it.  Off or on vpn ?
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39769645
nm, this worked for now.
Function IsVPNConnected()
   
   IsVPNConnected = False
   sComputer = "."

   Set oWMIService = GetObject("winmgmts:\\" _
    & sComputer & "\root\CIMV2")

   
   Set colItems = oWMIService.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapterConfiguration", , 48)

   
   For Each objItem In colItems

'Please check description of your VPN Connection by running command "ipconfig /all" on command-line.

    If (InStr(objItem.Description, "AnyConnect")) Then
     IsVPNConnected = objItem.IPEnabled
    End If

   Next
   

   If (IsVPNConnected) Then
    IsVPNConnected = MsgBox("I am Connected to VPN.")
   Else
    IsVPNConnected = MsgBox("I am Not Connected to VPN.")
   End If

End Function
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question