Jump to content
Sign in to follow this  
jezr74

Detect Subnet

Recommended Posts

jezr74

Hi there,

I'm having trouble working out a way to determine what subnet a script is running on, in which depending on the subnet it will perform different functions.

$LocalIP=@IPAddress1
if $LocalIP = "192.168.1." then IniWrite("C:\Program Files\Info\xp.ini", "XP", "Site", "Office1")
if $LocalIP = "192.168.2." then IniWrite("C:\Program Files\Info\xp.ini", "XP", "Site", "Office2")
if $LocalIP = "192.168.3." then IniWrite("C:\Program Files\Info\xp.ini", "XP", "Site", "Office3")
if $LocalIP = "192.168.4." then IniWrite("C:\Program Files\Info\xp.ini", "XP", "Site", "Office4")
$Site=IniRead("C:\Program Files\Info\xp.ini", "XP", "Site", "NOT FOUND")

The above does'nt work... I can make it work with > , but can prove unreliable. I'm not sure how to make it check a range of IPS...

Any guidance would be great...

thanks

Share this post


Link to post
Share on other sites
jefhal

Any guidance would be great...

thanks

Check out stringinstr to find a specific string inside the returned IP address. Also, what do you get when you run ipconfig /all on one of these machines? If they have more than one network device they will return more than one ip address...

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites
jezr74

Check out stringinstr to find a specific string inside the returned IP address. Also, what do you get when you run ipconfig /all on one of these machines? If they have more than one network device they will return more than one ip address...

Thank you for the pointer, working fine now!

$Subnet = StringLeft(@IPAddress1, 10)
if $Subnet = "192.168.1" then IniWrite("C:\Program Files\Info\xp.ini", "XP", "Site", "Office1")
if $Subnet = "192.168.2" then IniWrite("C:\Program Files\Info\xp.ini", "XP", "Site", "Office2")
if $Subnet = "192.168.3" then IniWrite("C:\Program Files\Info\xp.ini", "XP", "Site", "Office3")
if $Subnet = "192.168.4" then IniWrite("C:\Program Files\Info\xp.ini", "XP", "Site", "Office4")
$Site=IniRead("C:\Program Files\Info\xp.ini", "XP", "Site", "NOT FOUND")

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  

×