Page 1 of 1 1
Topic Options
#170518 - 2006-11-21 12:00 AM Subnets
tboyes Offline
Lurker

Registered: 2006-11-20
Posts: 3
i was using a script to identify where someone was logging in according to their IP as shown below.

IF $IP1and2 = " 10. 12"
Select
Case $ip3 = " 55"
$LOC="Test Site, VA"
USE $Netlogon @Lserver + "\NETLOGON"

Well now i'm running out of IP ranges so i have to start subnetting. How do i write it if i want to identify 10.12.55.1-62 255.255.255.192?

Top
#170519 - 2006-11-21 12:17 AM Re: Subnets
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Try this UDF GetIPInfo
Top
#170520 - 2006-11-21 03:53 AM Re: Subnets
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See the FAQ Forum under TCP/IP Primer, Part III - IP Addresses and KiXtart
_________________________
There are two types of vessels, submarines and targets.

Top
#170521 - 2006-11-21 07:58 AM Re: Subnets
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
wtf? ipranges from 10-scope are not enough for you?
how many "divisions" you actually have?

may I ask, just for curiocity, how do you apply those IP's? do you have dhcp's in all of the offices?
just trying to think how IP identification is better than just pure groups.
if done properly, they indeed can provide usable information but in most cases they are set in non-special fashion and thus do not provide any advantage over grouping.

Top
#170522 - 2006-11-21 02:58 PM Re: Subnets
tboyes Offline
Lurker

Registered: 2006-11-20
Posts: 3
We are world wide and our parent company in Sweden gave us the IP range from 10.12.48.0 -10.12.63.0

every new site that we open we just gave a 255.255.255.0 mask not thinking we were going to grow as much as we did. we have a centralized DHCP server for all our remote sites

Top
#170523 - 2006-11-21 03:02 PM Re: Subnets
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the problem is, how do you know if a computer resides in some subnet if you have centralised dhcp?
if a computer moves around, like laptops usually do, the information you might be able to bind to that computer is wrong.
or do you have some other method of setting the ip by the location?

just asking as I'm trying to understand how do you group the ip's to the actual sites.

Top
#170524 - 2006-11-21 03:33 PM Re: Subnets
tboyes Offline
Lurker

Registered: 2006-11-20
Posts: 3
assign them through AD Sites and Services. There is a Cisco router at each site with an IP helper on the ethernet interface
Top
#170525 - 2006-11-21 06:04 PM Re: Subnets
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Search for the IsInSubnet UDF in the UDFs section.

I use this with a table of subnets and my GetNetInfo UDF to do exactly what you are looking for. I'll post GetNetInfo here for your convenience, and post it to the UDF section tonight when I can properly format it.

Basically, GetNetInfo loads an INF file into an array, which provides subnet and other data. The file looks something like this:
Code:

10.0.0.0/24 Info_1 Info_2 Info_3
10.0.0.0/24 Info_1 Info_2 Info_3


Info_1 might be the short Site ID, Info_2 the primary software deployment server name, and Info_3 the long description for the site, just as an example. Make sure you delimit the file with Tabs, and that all lines have the same number of fields. I maintain it in an Excel spreadsheet, and then just select the data, copy it, and paste it into Notepad.

The GetNetInfo udf works like this -
Code:
GetNetInfo(ip_address [, FieldID] [, FilePath])


It reads the file - either from a default location or the one specified. It uses the IsInSubnet UDF to compare the target IP to the array of subnets, and returns the data from the corresponding record field that you specify. Thus, if the third column of your config file contained site names, you could use
Code:

$SiteName = GetNetInfo(Ping($Host), 3, '@SCRIPTDIR\netinfo.inf')



Glenn

GetNetInfo UDF follows:

Code:
 
;;
;;======================================================================
;;
;;FUNCTION GetNetInfo()
;;
;;ACTION Returns data by matching an IP address to a subnet list
;;
;;AUTHOR Glenn Barnas
;;
;;AUTHOR Version 2.0
;;
;;SYNTAX GetNetInfo(IP_Addr [, Field] [, File])
;;
;;PARAMETERS IP_Addr - an IP address of the local server
;;
;; Field (Optional) - Field in subnets.inf to return
;; The default is field 2 - Site Name
;;
;; File (optional) - Defines the location of the subnets.inf file
;; The default is %S_CONFIG%\subnets.inf
;;
;;REMARKS Allows an application to determine physical site-specific
;; information based on the target system's IP address.
;;
;;RETURNS The data in the specified or default field of the data file
;;
;;DEPENDENCIES IsInSubnet() UDF (SeaLeopard)
;; Subnets.inf file
;; In our application, the format of this file is:
;; 192.168.0.0/23 Local_SD_Server SiteName Description
;; ALL RECORDS MUST CONTAIN THE SAME NUMBER OF FIELDS!
;;
;; The first field must be the network address & subnet - all
;; other fields are application dependent, and any number of fields
;; can be supported.
;;
;; The file is found by default in the %S_CONFIG% folder. If it is not there,
;; the @SCRIPTDIR folder is checked. If the optional File value is specified,
;; the named file is read and no other locations are checked.
;;
;;
;;TESTED WITH NT4, W2K, WXP
;;
;;EXAMPLES
;;
;;UPDATES V1.2 - 02/01/04 - Check alternate location for config file
;; v2.0 - 11/02/06 - Combine GetWANSite and GetNetInfo functionality
;
Function GetNetInfo($_IP_Addr, OPTIONAL $_Field, OPTIONAL $_File)

Dim $_, $_Idx, $_FH, $_Line, $_CFile
Dim $_aZones[500], $_aData[500], $_aTmp, $_aFound


; Insure that the Field var is a non-zero numeric value - default is 2
$_Field = IIf(Val($_Field) = 0, 2, Val($_Field))

; If $_File was specified, verify the file exists. Exit with File Not Found if it doesnt.
; otherwise, check for the standard file in default locations
If $_File
If Exist($_File)
$_CFile = $_File
Else
Exit 2 ; file not found!
EndIf
Else
; Subnet definition file should be in a std location, but could be in SCRIPTDIR
; for other installations - accept SCRIPTDIR only if not in std location
Select
Case Exist('%S_CONFIG%\Subnets.inf')
$_CFile = '%S_CONFIG%\Subnets.inf'

Case Exist('@SCRIPTDIR\Subnets.inf')
$_CFile = '@SCRIPTDIR\Subnets.inf'

Case 1
; FILE NOT FOUND
Exit 2 ; exit if file was not found

EndSelect

EndIf ; File

; the subnet definition file exists - load it into a pair of arrays
$_Idx = 0
$_FH = FreeFileHandle()
If Open($_FH, $_CFile, 2) = 0
$_Line = ReadLine($_FH)
While @ERROR = 0
$_aTmp = Split($_Line, Chr(9)) ; split the line into subnet and data
; Verify that the Field value is valid
If $_Field > UBound($_aTmp)
Exit 87 ; invalid argument was specified
EndIF

$_aZones[$_Idx] = $_aTmp[0] ; build the subnet array
$_aData[$_Idx] = $_aTmp[$_Field] ; build the data array
$_Idx = $_Idx + 1
$_Line = ReadLine($_FH) ; read the next line
Loop
EndIf
$_ = Close($_FH) ; close the file

ReDim Preserve $_aZones[$_Idx - 1] ; reduce the array sizes
ReDim Preserve $_aData[$_Idx - 1]


; see if the IP address given exists in any of the defined subnets
; This function returns an array - one element will be TRUE, corresponding
; to the array position of the matching subnet
$_aFound = IsInSubnet($_IP_Addr, $_aZones)


; search the returned array for a '1' value. If found, a corresponding
; server name should be defined in the servers array.
$_Idx = AScan($_aFound, 1)


; return the associated data if a match was found.
If $_Idx <> -1
$GetWANSite = $_aData[$_Idx]
Exit 0
EndIF


; exit with error and no data if not found
Exit 1

EndFunction






Top
#170526 - 2006-11-21 10:24 PM Re: Subnets
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
or just moan()
Top
#170527 - 2006-11-22 12:46 AM Re: Subnets
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Quote:

or just moan()





LOL - I'm sure that is a perplexing statement for a new user.

Quote:

;FUNCTION MOAN()
;
;ACTION Depending on the input, returns IP-addresses, Subnets,
; NetworkIDs or IsInSubnet boolean.
;
;AUTHORS
; Jooel Nieminen (jooel_nieminen@gwspikval.com)
; Howard Bullock (habullock@comcast.net)
; Jens Meyer (sealeopard@usa.net)
; Patrick Rutten (MightyR1@hotmail.com)
;
;VERSION 1.0.



 
Moan() - Mother Of All Networks
 

Top
#170528 - 2006-11-22 12:58 AM Re: Subnets
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
heh, well...
it's not any harder to use than any isinsubnet and it has never had no dependencies.

the hardest issue with it is that it has too much functionality in so small code-block.
but the usage is simple, iirc.

Top
#170529 - 2006-11-22 01:19 AM Re: Subnets
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
I wasn't meaning the complexity of the code Jooel. I meant that with just a name like MOAN and no link to code or explantion of code, one that is new here might think you were saying to just MOAN about it.
 

Top
#170530 - 2006-11-22 01:21 AM Re: Subnets
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I just looked at MOAN and the following link is not working...
http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=14;t=000748;p=4#000083

Would like to read more about it... However.

Top
#170531 - 2006-11-22 01:48 AM Re: Subnets
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Well none of the links currently work.
Must have been posted before one of the board upgrades.
 

Top
#170532 - 2006-11-22 02:03 AM Re: Subnets
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Please try the following links.

KiXgolf: MOAN - Mother Of All Networks
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=100163

Quote:

=============
The Challenge
=============
  
You are to create the Mother Of All Networks (MOAN) UDF.
This UDF will provide certain network information depending on the parameters passed to it.
The challenge will be run as a private coding challenge from
Friday, May 23, 3pm EST to Friday, May 30, 3pm EST.
A second public coding phase will start on Friday, May 30 and end on Wednesday, June 4, 3pm EST.
 
The task is to generate the corresponding output based on the input of either two or
three of the parameters IP Address, Network ID, and Subnet Mask. Specifics are provided
in section "Inputs & Outputs".






KIXgolf: MOAN(), Part II
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=100502

MightyR1 commented the code on page 4 of Part II
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=100502&page=0&fpart=4
 
The Finalized UDF Code
Moan() - Mother Of All Networks
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=83638




 

Top
#170533 - 2006-11-22 04:50 AM Re: Subnets
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Thanks Doc
Top
#170534 - 2006-11-22 10:21 AM Re: Subnets
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, moan.
yeah, that should work too

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1172 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.077 seconds in which 0.035 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org