Sign in to follow this  
Followers 0
gleem

Better way to determine subnet.

4 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Have you thought about using StringSplit()?

Edit:

Example of return:

#include <array.au3>
$aArray = StringSplit(@IPAddress1, '.')
_ArrayDisplay($aArray, '')
Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

I was more thinking just:
$aArray = StringSplit(@IPAddress1, '.')
MsgBox(64, 'Subnet Is:', $aArray[3])

[center]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.[/center]

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