#159884 - 2006-03-28 09:33 AM
different options per iprange
|
Blubba
Fresh Scripter
Registered: 2006-03-27
Posts: 7
|
Hi there,
i've got a question about how i'll be able to give specific printers per iprange.
i've already tried something like:
function isiniprange($ipaddress,$iprangearray)
$ipaddress=@ipaddress0 $iparray[0]=10.18.132.0/254 if ISINIPRANGE($ipaddress,$iparray) ADDPRINTERCONNECTION ("\\nl-lee-gs01\prn0301") endif endfunction
ipexamples are 10.10.34.0 to 220 (first iprange) 10.10.35.0 to 220 (second) and so on...
i already looked to a number of posts but they only contain scripts of how to give 1 thing to 1 specific iprange.
what i'm trying to get is to have 4 specific ipranges and to have specific printers being added per iprange.
could someone help me?
(btw sorry for the english.. )
|
Top
|
|
|
|
#159885 - 2006-03-28 09:45 AM
Re: different options per iprange
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11625
Loc: CA
|
Hello and Welcome to the board Blubba.
Not sure about that UDF as I've not used it myself and a bit too lazy to go look up it's usage, but here is a simple method that should work.
Code:
Select Case InStr(Join(Split(@IPAddress0,' '),''),'10.18.132') 'Your IP is within the range 10.18.132 so we will install a printer ' ? Case InStr(Join(Split(@IPAddress0,' '),''),'10.10.34') 'Your IP is within the range 10.10.34 so we will install a printer ' ? Case 1 'Not within any correct IP Range so no printer installed. ' ? EndSelect
Notice that we are removing the padding (spaces in the IP) from the lookup.
|
Top
|
|
|
|
#159886 - 2006-03-28 09:49 AM
Re: different options per iprange
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Hi and welcome to this board.
This should do the job for you. Of course it should be altered to really add the printers but you can see exactly in what section the system ends up.
Code:
;Get the third octet of the ip address. $ip = SubStr(@IPADDRESS0, 9, 3) ; ;Remove spaces. $ip = Trim($ip)
;Do stuff based on third octet. Select Case $ip = "34" ?"PC is in 34 subnet." ?"Add printers from 34 subnet." Case $ip = "35" ?"PC is in 35 subnet." ?"Add printers from 35 subnet." Case $ip = "36" ?"PC is in 36 subnet." ?"Add printers from 36 subnet." Case $ip = "37" ?"PC is in 37 subnet." ?"Add printers from 37 subnet." EndSelect
Edited by Mart (2006-03-28 11:26 AM)
|
Top
|
|
|
|
#159889 - 2006-03-28 11:16 AM
Re: different options per iprange
|
Blubba
Fresh Scripter
Registered: 2006-03-27
Posts: 7
|
ok very glad you can all give such a quick reply the only thing i can't get right it seems is the substring the actual ip = 10. 18.132.0 and without te spaces i would think the substring wil have to be:
SubStr(@IPADDRESS0, 5, 3)
what am i seeing wrong here?
|
Top
|
|
|
|
#159891 - 2006-03-28 11:33 AM
Re: different options per iprange
|
Blubba
Fresh Scripter
Registered: 2006-03-27
Posts: 7
|
Quote:
@ipaddress0 will always return the ip address as 15 characters. So if your ip address is 10.0.0.1 @ipaddress will return space10.spacespace0.spacespace0.spacespace1 It will always be in xxx.xxx.xxx.xxx format so to get the third octet you should start reading at character 9 and then read three characters. Removing the spaces will then give you the "clean" value.
I also made a mistake in my post (two actually) 
Your line should look like this to get the third octet in the $rc variable.
Code:
$rc = SubStr(@IPADDRESS0, 9, 3)
Thanx (bedankt) Mart...
this helped me out a lot the problem is fixed...
|
Top
|
|
|
|
#189140 - 2008-08-18 03:12 AM
Re: different options per iprange
[Re: Blubba]
|
MattColeman
Fresh Scripter
Registered: 2008-05-19
Posts: 12
Loc: Kitchener-Waterloo, ON
|
you guys rock - this script is resolving a big headache
I do have one question though: how do I get this subnet trimmed?
$subnet = SubStr(@IPADDRESS0, 1, 11)
$subnet = Trim($subnet) <<<<<< Doesn't work???
Select Case $subnet = "192.237. 4" ?"subnet is not trimmed." Case $subnet = "192.237.4" ?"subnet is trimmed." EndSelect
**I'm getting the first argument all the time**
I should mention that I can't use just the third octet as we have both private c's and public c's on our network... (i.e. 192.237.4.xxx & 192.168.4.xxx)
Edited by MattColeman (2008-08-18 03:46 AM) Edit Reason: added paragraph on bottom
|
Top
|
|
|
|
#189141 - 2008-08-18 03:22 AM
Re: different options per iprange
[Re: MattColeman]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4557
Loc: USA
|
Welcome to board.
If you look through this thread, find the post by NTDoc (here) where he uses Join-Split in a select statement. If you use that with your ips, all the work is done.
If you have any other questions, please start your own thread, and we'll be glad to help.
|
Top
|
|
|
|
#189149 - 2008-08-18 06:12 PM
Re: different options per iprange
[Re: Allen]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Or use EnumIPInfo() to catch the IP Addresses
;Script Options
$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
BREAK ON
;Declare variables
DIM $IPAddresses, $IPAddress
DIM $i
;Initialize variables
$i = 0
;Find all IP Addresses on the computer
$IPAddress = EnumIPInfo($i,0,1)
While not @ERROR
;Create string of IP Addresses delimited by pipe sign
If not $IPAddresses = ''
$IPAddresses = $IPAddresses + '|'
EndIf
$IPAddresses = $IPAddresses + $IPAddress
$i = $i + 1
$IPAddress = EnumIPInfo($i,0,1)
Loop
;Create array of IP Addresses
$IPAddresses = Split($IPAddresses,'|')
;Show IP Addresses in array
For Each $IPAddress In $IPAddresses
? '- ' $IPAddress
Next
;Press any key to continue
Get $SO
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 323 anonymous users online.
|
|
|