Page 1 of 1 1
Topic Options
#152264 - 2005-11-25 04:50 PM Identify subnet
lawe009 Offline
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
#152265 - 2005-11-25 04:54 PM Re: Identify subnet
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There is a FAQ on that and several UDFs posted.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152266 - 2005-11-29 04:15 PM Re: Identify subnet
lawe009 Offline
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 Offline
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)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#152268 - 2005-11-29 04:45 PM Re: Identify subnet
lawe009 Offline
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#152270 - 2005-11-29 04:55 PM Re: Identify subnet
Radimus Moderator Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#152271 - 2005-11-29 05:06 PM Re: Identify subnet
lawe009 Offline
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 Offline
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])
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#152273 - 2005-11-29 05:33 PM Re: Identify subnet
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
true, but I assumed it was space from the code in the first post
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#152274 - 2005-11-29 05:35 PM Re: Identify subnet
lawe009 Offline
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 Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
in the split statement
$oct4 = val(split($ip,'.')[3])
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#152276 - 2005-11-29 06:20 PM Re: Identify subnet
lawe009 Offline
Fresh Scripter

Registered: 2004-04-14
Posts: 36
Works perfect, thanx!
Lars

Top
#152277 - 2005-11-29 10:17 PM Re: Identify subnet
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
No need for LTrim() since Val() ignores the space characters anyway.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#152278 - 2005-11-29 10:49 PM Re: Identify subnet
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I know
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#152279 - 2005-11-30 01:39 AM Re: Identify subnet
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You actually have the subnet mask, you just don't know. You've divided your set of IPs into four subnets 1-63, 64-127,...

Thus, the corresponding subnet mask would be 255.255.255.192. You can then use e.g.
Code:

IsInSubnet(@IPADDRESS0,'10.2.129.64','255.255.255.192')



Edited by sealeopard (2005-11-30 01:42 AM)
_________________________
There are two types of vessels, submarines and targets.

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
0 registered and 837 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.07 seconds in which 0.027 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