Sign in to follow this  
Followers 0
MikeDub

Search array of subnets against current IP

6 posts in this topic

Hello All,

First off - What I'm trying to do.

We are using Quest AppPortal for published applications.  Our requirement is that the end user has to be connected to our network (LAN or WAN) in order to use it (hate company politics).

Now as many times as I have explained to end users that if they are not on our network (within the confines of our buildings) that they have to connect to VPN first prior to launching this "AppPortal", and as you can assume with many it just does not sink in.

What I am hoping

So, I am currently trying to think of the best way to go about this.

A First thought

A thought I had was to create an array containing a list of each of our networks

Then an array consisting of @ipaddress1, and @ipaddress2

Then search for the first three octets of that second array within the first array

The check to see if anything in that second array matches any of the items in the first array

If it exists simply launch that AppPortal and if not Launch VPN first, then once VPN gets connected launch AppPortal

Example

#include <array.au3>
 
Local $aSubnets[4]
$aSubnets[0] = "10.0.4"
$aSubnets[1] = "192.168.4"
$aSubnets[2] = "192.168.5"
$aSubnets[3] = "192.35"
 
Local $aCurrentIP = [@IPAddress1, @IPAddress2]
 
Local $iIndex = _ArraySearch( This is where I get lost )

My Problem

I am not sure how I can go about this using this method.  First off I'm not sure how to check if the first 2 or 3 octets match those in $aSubnets (suppose I could grow that $aSubnets array to include all options of that 192.35.x.x network so I have three octets all around)

$aSubnets[0 through 2] containing 3 octets and the last only containing 2   **  [0] is our VPN, [1 and 2] wireless networks, and [3] being wired **

I cannot only search the first 2 octets as many home networks as you all know would probably consist of 192.168.x.x in the first 2 octets as well

Any help appreciated

Share this post


Link to post
Share on other sites



Hi, MikeDub. I guess you could do something like this (example using the VLANs in place at my current customer location):

Select
        Case StringLeft(@IPAddress1, 8) = "10.10.10"
            MsgBox(0, "", "On the network: VLAN 1")
        Case StringLeft(@IPAddress1, 8) = "10.10.20"
            MsgBox(0, "", "On the network: VLAN 2")
        Case StringLeft(@IPAddress1, 8) = "10.10.30"
            MsgBox(0, "", "On the network: VLAN 3")
        Case StringLeft(@IPAddress1, 8) = "10.10.40"
            MsgBox(0, "", "On the network: VLAN 4")
        Case Else
            MsgBox(0, "", "Not on the network")
    EndSelect

but it is not the cleanest way, and would need to be updated when new subnets are added. It may be easier just to look for the presence of the VPN connection itself. Are you running just a generic PPTP VPN, or some third party like Juniper or Cisco? If it is the latter, you should be able to check the state of the VPN through the local client, and launch your app if true.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

It may be easier just to look for the presence of the VPN connection itself. Are you running just a generic PPTP VPN, or some third party like Juniper or Cisco? If it is the latter, you should be able to check the state of the VPN through the local client, and launch your app if true.

 

Unfortunately, I cannot just check for the VPN connection itself as we use this AppPortal both internally and externally; hence, the reason I'm giving myself this headache.

To answer the question on what VPN...  Some of the users are using the Cisco AnyConnect Secure Mobility Client and others are using an older version

Share this post


Link to post
Share on other sites

OK

Decided to go with the notion of using Select Case as JLogan3o13 had suggested (doesn't look too very dirty (as of yet))

Now, my problem is trying to determine once the VPN connection has been established.

My issue there is that some people are using Cisco VPN Client 5.x.x and some on Cisco AnyConnect

Currently I've added a Sleep statement in there and then check the @ipaddress2 connection; however, I really don't like the notion of using a 'sleep' statement due to there being too many times where the time I've chosen being either too long in some instances or too short in others.

Due to the various ways people have their given VPN client connection configured I can't really use a WinWaitActive() either

Any ideas on how I could check this part?

What I have is:

; Set default connection state
$sConnection = "OFF"
 
; VPN Client Variables
$sAnyConnect = @ProgramFilesDir & "\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"
$sVPNClient = @ProgramFilesDir & "\Cisco Systems\VPN Client\vpngui.exe"
 
; Determine which VPN Connection to use ** if needed **
If FileExists( $sVPNClient) Then
 $sClientConnection = $sVPNClient
Else
 $sClientConnection = $sAnyConnect
EndIf
 
 
Select
 Case StringLeft( @IPAddress1, 5 ) = "1.1.1"
  $sConnection = "ON"
 Case StringLeft( @IPAddress1, 5 ) = "2.2.2"
  $sConnection = "ON"
 Case StringLeft( @IPAddress1, 5 ) = "3.3.3"
  $sConnection = "ON"
 Case StringLeft( @IPAddress2, 6 ) = "10.0.4"
Case Else
  $sConnection = "OFF"
EndSelect
 
if $sConnection = "ON" Then
 Run( @ProgramFilesDir & "\Quest Software\vWorkspace Client\pnap32.exe" ) 
Else
 Run( $sClientConnection )
 Sleep( 10000)
 if StringLeft( @IPAddress2, 6 ) = 10.0.4 Then
  Run( @ProgramFilesDir & "\Quest Software\vWorkspace Client\pnap32.exe")
 EndIf
EndIf

 

I would like to get away from that Sleep statement - Any ideas?

 

Share this post


Link to post
Share on other sites

A couple of things: I notice your last Case statement, before the Case Else, doesn't do anything (10.0.4). Also, if you cannot use WinWaitActive, what about looking for the process? ProcessExists or running a ProcessList may give you what you seek.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

A couple of things: I notice your last Case statement, before the Case Else, doesn't do anything (10.0.4).

 

Imagine it doing something - I simply forgot to type that something in...  It should be the same as the others

I'll check in to the process thing.  Not sure what process to check for with the various VPN clients that connect up; however, that is what I will try to use ProcessList for.

Thanks for the Help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0