Page 1 of 1 1
Topic Options
#72592 - 2003-01-13 09:41 PM Help - what's wrong with this script
jimmyd Offline
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
#72593 - 2003-01-13 09:44 PM Re: Help - what's wrong with this script
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
$3rd = VAL(SUBSTR(@IPAddress0,9,3))
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#72594 - 2003-01-13 09:55 PM Re: Help - what's wrong with this script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See also TCP/IP Primer, Part I - IP Addresses
_________________________
There are two types of vessels, submarines and targets.

Top
#72595 - 2003-01-30 10:51 PM Re: Help - what's wrong with this script
Glenn Barnas Administrator Offline
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! \:D

Top
#72596 - 2003-01-30 10:59 PM Re: Help - what's wrong with this script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
glenn, you have pretty many cents there [Wink]
_________________________
!

download KiXnet

Top
#72597 - 2003-01-30 11:02 PM Re: Help - what's wrong with this script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Glenn:

The TCP/IP Primer referenced above contains UDFs that perform all kinds of network identifications.
_________________________
There are two types of vessels, submarines and targets.

Top
#72598 - 2003-01-31 02:13 PM Re: Help - what's wrong with this script
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Guys - I subscribe to the old adage "give someone a fish, you feed them for a day, teach them to fish, you feed them for life." That's why my $0.02 usually winds up so much higher. [Wink]

This question was first posted in the New to Kix (???) section, so I assumed that more background woulld be helpful. It looked like he reposted his question here.

Jens - I looked at the link - scratched my head and wondered why an IP tutorial would be helpful.. I totally missed the link to the UDFs in Part III.. Those are really cool - I'll be spending more time reviewing them myself. "Duh!" on my part.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#72599 - 2003-01-31 03:29 PM Re: Help - what's wrong with this script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Parts II & III are referenced at the top of the thread. However, I will also put additional links at the bottom of the thread.
_________________________
There are two types of vessels, submarines and targets.

Top
#72600 - 2003-02-05 01:01 PM Re: Help - what's wrong with this script
MCA Offline
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.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#72601 - 2003-02-08 08:32 AM Re: Help - what's wrong with this script
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#72602 - 2003-02-08 04:12 PM Re: Help - what's wrong with this script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Or even
code:
$subnet=trim(split(@IPADDRESS,'.')[2])

_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 756 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.063 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