#152264 - 2005-11-25 04:50 PM
Identify subnet
|
lawe009
Fresh Scripter
Registered: 2004-04-14
Posts: 36
|
Hi, I have a script that maps network printers in the same subnet as the client logs in. This works fine with subnetmasks 255.255.255.0 . Now however there are subnets with 255.255.255.192 and 255.255.255.128 and using the same third octet if thats the correct name. Ie 10.2.129.1 - 10.2.129.62 10.2.129.65 - 10.2.129.126 10.2.129.129 - 10.2.129.190
How do I identify this? The method I´m using gives the same result for these subnet 10.2.129.
See script below This is in a Citrix enviroment and thats why I use the %CURRENT_CLIENTIP% variable
Code:
; Printmappings depend on subnet
$ip = expandenvironmentvars('%CURRENT_CLIENTIP%') $ipnospaces = Join(Split($IP," "),"")
If InStr ($ipnospaces,"192.168.0.") Goto "loc1" Endif
If InStr ($ipnospaces,"192.168.50.") Goto "loc2" Endif
If InStr ($ipnospaces,"192.168.51.") Goto "loc3"
:loc1 Addprinterconnection ("\\srv\loc1prnt1") Addprinterconnection ("\\srv\loc1prnt2")
:loc2 Addprinterconnection ("\\srv\loc2prnt1") Addprinterconnection ("\\srv\loc2prnt2")
:loc3 Addprinterconnection ("\\srv\loc3prnt1") Addprinterconnection ("\\srv\loc3prnt2")
Endif
|
|
Top
|
|
|
|
#152266 - 2005-11-29 04:15 PM
Re: Identify subnet
|
lawe009
Fresh Scripter
Registered: 2004-04-14
Posts: 36
|
I´ve got the subnets working however I can´t get the script to enumerate the last number to work. Whats wrong with this? Code:
If ($decip>=1 AND $decip<=62) Goto "Site1" Else
IF ($decip>=65 AND $decip<=126) Goto "Site2" Else
IF ($decip>=129 AND $decip<=190) Goto "Site3" Else Goto "Nosite"
Edited by lawe009 (2005-11-29 04:17 PM)
|
|
Top
|
|
|
|
#152267 - 2005-11-29 04:32 PM
Re: Identify subnet
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Please review the manual and your IF..Else..Endif contructs. you have no ENDIF's anywhere.
The CalcLogicalSubnet() or other UDF would be much more useful to you especially when the subnet definitions / masking change as they always do.
Edited by Howard Bullock (2005-11-29 04:33 PM)
|
|
Top
|
|
|
|
#152268 - 2005-11-29 04:45 PM
Re: Identify subnet
|
lawe009
Fresh Scripter
Registered: 2004-04-14
Posts: 36
|
Thanx for your answer. The problem is I only have the IP adress not the subnet as I´m using the clients IP in citrix. I use a program to retieve it that don´t supply the subnet mask. It now seems that it isn´t the enumeration thats the problem but how I retrieve the last octet from th IP-adress.
|
|
Top
|
|
|
|
#152269 - 2005-11-29 04:48 PM
Re: Identify subnet
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You haven't shown us what you are currently doing in your attempt to get the data. Please show us your data and the process you currently use.
|
|
Top
|
|
|
|
#152270 - 2005-11-29 04:55 PM
Re: Identify subnet
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$ip = expandenvironmentvars('%CURRENT_CLIENTIP%') $oct4 = val(split($ip)[3]) select case $oct4 < 63 Addprinterconnection ("\\srv\loc1prnt1") Addprinterconnection ("\\srv\loc1prnt2")
case $oct4 < 127 Addprinterconnection ("\\srv\loc2prnt1") Addprinterconnection ("\\srv\loc2prnt2")
case $oct4 < 191 Addprinterconnection ("\\srv\loc3prnt1") Addprinterconnection ("\\srv\loc3prnt2")
case $oct4 < 255 Addprinterconnection ("\\srv\loc4prnt1") Addprinterconnection ("\\srv\loc4prnt2")
endselect
|
|
Top
|
|
|
|
#152271 - 2005-11-29 05:06 PM
Re: Identify subnet
|
lawe009
Fresh Scripter
Registered: 2004-04-14
Posts: 36
|
Howard I´m using 2 UDF:s and it seems that Radimus script does that with 10:th of code. I´ll have a look at Radimus script. Thank you both for your input!
Edited by lawe009 (2005-11-29 05:07 PM)
|
|
Top
|
|
|
|
#152272 - 2005-11-29 05:25 PM
Re: Identify subnet
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Rad-man, as I do not know what the exact format of the $ip really is...should you be splitting on a "." and using Ltrim if needed? $oct4 = val(split($ip)[3])
|
|
Top
|
|
|
|
#152273 - 2005-11-29 05:33 PM
Re: Identify subnet
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
true, but I assumed it was space from the code in the first post
|
|
Top
|
|
|
|
#152274 - 2005-11-29 05:35 PM
Re: Identify subnet
|
lawe009
Fresh Scripter
Registered: 2004-04-14
Posts: 36
|
Question is directed to Radimus but the $IP is a IP looking like 192.168.0.10 . The $Oct4 gives just a 0 whatever IP I´m using. Did you have another suggestion to retrieve the $Oct4 . Thanx in advance.
|
|
Top
|
|
|
|
#152275 - 2005-11-29 06:01 PM
Re: Identify subnet
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
in the split statement $oct4 = val(split($ip,'.')[3])
|
|
Top
|
|
|
|
#152276 - 2005-11-29 06:20 PM
Re: Identify subnet
|
lawe009
Fresh Scripter
Registered: 2004-04-14
Posts: 36
|
Works perfect, thanx! Lars
|
|
Top
|
|
|
|
#152278 - 2005-11-29 10:49 PM
Re: Identify subnet
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I know
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 633 anonymous users online.
|
|
|