gleem Posted February 23, 2007 Posted February 23, 2007 I am looking for a better way to determine the subnet of all my networks as users log in. Below is the code I wrote.. It works but runs into problems. for example.. I trim the last digits on the right hand side. The problem I have is if a persons ip address was: 192.168.10.5, 192.168.10.50 it would trim to much thus i can not detect it. or there ip address might be 192.168.150.10 the number I am after is: XXX.XXX.This Set.XXX Here is currently how I do it. ------------------------------- ; Checks IP address and trim last 3 numbers to determine location. $checkSubnet = StringTrimRight(@IPAddress1,3) ; Check Location and Assign Variables If $checkSubnet = "192.168.10." Then $serverLocation = "Location 1" EndIf If $checkSubnet = "192.168.20." Then $serverLocation = "Location 2" EndIf ------------- any idea?
Moderators SmOke_N Posted February 23, 2007 Moderators Posted February 23, 2007 (edited) Have you thought about using StringSplit()? Edit: Example of return:#include <array.au3> $aArray = StringSplit(@IPAddress1, '.') _ArrayDisplay($aArray, '') Edited February 23, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
gleem Posted February 23, 2007 Author Posted February 23, 2007 Have you thought about using StringSplit()? Edit: Example of return:#include <array.au3> $aArray = StringSplit(@IPAddress1, '.') _ArrayDisplay($aArray, '') Thank you.. so basically it will end up like this: #include <array.au3> $aArray = StringSplit(@IPAddress1, '.') ;_ArrayDisplay($aArray, '') $sArrayString = _ArrayToString( $aArray,"", 3, 3 ) MsgBox( 4096, "Subnet Is:", $sArrayString ) Exit
Moderators SmOke_N Posted February 23, 2007 Moderators Posted February 23, 2007 Thank you.. so basically it will end up like this: #include <array.au3> $aArray = StringSplit(@IPAddress1, '.') ;_ArrayDisplay($aArray, '') $sArrayString = _ArrayToString( $aArray,"", 3, 3 ) MsgBox( 4096, "Subnet Is:", $sArrayString ) ExitI was more thinking just:$aArray = StringSplit(@IPAddress1, '.') MsgBox(64, 'Subnet Is:', $aArray[3]) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now