#170518 - 2006-11-21 12:00 AM
Subnets
|
tboyes
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
MM club member
   
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
|
|
Top
|
|
|
|
#170521 - 2006-11-21 07:58 AM
Re: Subnets
|
Lonkero
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
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
|
|
|
|
#170524 - 2006-11-21 03:33 PM
Re: Subnets
|
tboyes
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
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
|
|
|
|
#170527 - 2006-11-22 12:46 AM
Re: Subnets
|
NTDOC
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
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
|
|
|
|
#170532 - 2006-11-22 02:03 AM
Re: Subnets
|
NTDOC
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
|
|
|
|
#170534 - 2006-11-22 10:21 AM
Re: Subnets
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
oh, moan. yeah, that should work too
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1172 anonymous users online.
|
|
|