Jump to content

Better way to determine subnet.


gleem
 Share

Recommended Posts

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?

Link to comment
Share on other sites

  • Moderators

Have you thought about using StringSplit()?

Edit:

Example of return:

#include <array.au3>
$aArray = StringSplit(@IPAddress1, '.')
_ArrayDisplay($aArray, '')
Edited 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.

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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])

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...