#72592 - 2003-01-13 09:41 PM
Help - what's wrong with this script
|
jimmyd
Lurker
Registered: 2003-01-13
Posts: 2
|
The script below doesn't work at all. I want the IP address to look at the 3rd octet, and if it's 10, then the user is on the local domain and that script should run. Alternatively, if remote then the other script runs. I am logging in locally and nothing! Thanks, Jim
$address=@IPADDRESS0 $subnet=SubStr($address,0,2)
If $subnet="10" $NETWORK=LOCAL
Else $NETWORK=REMOTE
EndIf
If $NETWORK=LOCAL $ld = "@lserver\netlogon" CALL "$ld\local.kix"
EndIf
If $NETWORK=REMOTE $ld = "@lserver\netlogon" CALL "$ld\remote.kix" EndIf
|
|
Top
|
|
|
|
#72595 - 2003-01-30 10:51 PM
Re: Help - what's wrong with this script
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
The "@ipaddress#" macro returns a 15 character string containing the IP address. The address 1.1.1.1 would look like: "1 .1 .1 .1 " - note that each octet has three characters, even if they are spaces. You might use the split command to create an array: $aryIP = Split(@IPADDRESS0, ".", -1)
This will place each string of three chars (with spaces) into an array element. Remembering that Arrays start with zero, $aryIP[2] would contain "10 " (using your assumption). Lets assign that array value to a variable, just to keep the Var names straight.. $subnet = $aryIP[2]
The simpler alternative - $subnet = SubStr(@IPADDRESS0, 9, 3) - also places characters 9-12 into the variable. I illustrated the split command because it is powerful and often overlooked. It might even be preferred in this situation if you needed to examine multiple octets.
Testing the variable from either method to be equal to "10" would fail, because the variables actually contain the trailing space!
You could account for this: If $subnet = "10 " but this isn't good practice.. It's too easy to overlook the space when making future modifications.
You could convert to a number: $subnet = Val($subnet) Or, you could remove the spaces: $subnet = Trim($subnet)
Now testing for equality with "10" would work, and the rest of your script should function.
A few comments from an old hacker.. developing a style is important, especially when you review your code months later (or when you ask someone else to look it over).
* Make variable names stand out - use $CAPS * Use ID references for special vars, like arrays: $aryADDRESS * Indent your IF and LOOPing statements so you can easily tell where they begin and end. * Use comments liberally. Go back and review a script you wrote 6 months ago and you'll understand what I mean.
Well, accounting for inflation, that's my $0.56!
Hope it helps.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#72600 - 2003-02-05 01:01 PM
Re: Help - what's wrong with this script
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,
Welcome to the board.
We have restyle your script a little bit. In some situations you are using additional variables which aren't really necessary. Also we see a strange way of string assignment. Please use quotations by string. Possible that the current free-format situation will be removed.
Version 1
code:
$subnet=SubStr(@ipaddress0,9,3) IF ($subnet = " 10") $network="local" ELSE $network="remote" ENDIF
IF ($network = "local") CALL "@lserver\netlogon\local.kix" ENDIF IF ($network = "remote") CALL "@lserver\netlogon\remote.kix" ENDIF
Version 2 (a shorter version)
code:
IF (SubStr(@ipaddress0,9,3) = " 10") CALL "@lserver\netlogon\local.kix" ELSE CALL "@lserver\netlogon\remote.kix" ENDIF
greetings.
|
|
Top
|
|
|
|
#72601 - 2003-02-08 08:32 AM
Re: Help - what's wrong with this script
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
A quick suggestion -
Instead of: code:
$subnet=SubStr(@ipaddress0,9,3) IF ($subnet = " 10") ..
You can do: code:
$subnet=Ltrim(SubStr(@ipaddress0,9,3)) IF ($subnet = "10")
HTH,
Kent
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 756 anonymous users online.
|
|
|