Sign in to follow this  
Followers 0

Ip Address Compare

2 posts in this topic


Would appreciate any thoughts, feedback or help that anyone can offer on this. I am looking for a way to compare the 2nd and/or 3rd octets of a computers IP Address to a set list and perform an action (Func Call)based based on the comparison. Here is the background. Our internal network has roughly +400 local LAN's across the country, each connected via WAN to 1 of 11 'Core' sites. Each core site and all Local LAN's share the same 2nd octet range of the Class B subnet. Example:

Core Site 1 - IP Address Assignment 11.22.xx.xx

Local LAN 1 - 11.22.33.xx

Local LAN 2 - 11.22.44.xx

Core Site 2 - IP Address Assignment 11.33.xx.xx

Local LAN 4 - IP Address Assignment 11.33.33.xx

Local LAN 5 - IP Address Assignment 11.33.44.xx

Thus, if the workstations local IP Address is it would be connected to 'Core Site 1'.

I guess, more or less, I need a way to parse the second IP octet but I'm not sure what function to use. I would like to keep the process entirely within the AutoIt script if possible, i.e. using the @IPADDRESS variable and comparing to a list of subnets and doing a If Else routine. Just not sure about the parsing of the second octet. :whistle:

Any thoughts would be appreciated and thanks in advance.

Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)

StringSplit is your friend :whistle:

$ip1 = "11.22.33.xx"
$ip2 = "11.22.44.xx"
$lan1 = StringSplit($ip1, ".")
$lan2 = StringSplit("$ip2", ".")
If $lan1[2] = $lan2[2] Then MsgBox(0,"","The second octets are equal")

You could also use StringInStr to get the position of the dot, then strip off the octets using StringLeft, StringTrimLeft, StringRight, etc.

Hope that helps

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

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