#149612 - 2005-10-11 04:25 AM
If instr(@ipaddress) ???
|
MarcD
Fresh Scripter
Registered: 2005-10-06
Posts: 7
|
Is there a way to perform an if statement according on a certain string in an IP address. (Like Below) I am fairly new to coding so...;
IF instr(@ipaddress0) = "172.18.48." AT (21,1) "Connected via VPN, Not mapping office Printers" sleep 2 exit else .... This doesnt work, so surely there is a better way to do this...
|
Top
|
|
|
|
#149615 - 2005-10-11 06:26 AM
Re: If instr(@ipaddress) ???
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
As Les mentioned, don't forget the spaces returned from @IPADDRESS0
Code:
Break On If InStr(Join(Split(@ipaddress0,"172.18.48"),' '),'') 'IP is valid' ? Exit 1 Else 'IP is not in range' ? EndIf
|
Top
|
|
|
|
#149616 - 2005-10-11 07:07 AM
Re: If instr(@ipaddress) ???
|
MarcD
Fresh Scripter
Registered: 2005-10-06
Posts: 7
|
Quote:
Instr() returns either 0 if it doesn't find the string you are looking for or it returns the location within the string...
So if the address is "172.18.100.100", it would return a 0
What would it return if the address was "172.18.48.12"
|
Top
|
|
|
|
#149618 - 2005-10-11 07:19 AM
Re: If instr(@ipaddress) ???
|
MarcD
Fresh Scripter
Registered: 2005-10-06
Posts: 7
|
Whilst playing around, I have come up with;
Code:
$address = instr(@ipaddress0, "172.18.48.") if $address = 1 AT (8,10) "You are Logged on Locally. Starting Script" sleep 2 goto start endif
if $address = 0 AT (8,10) "You are Logged on via the VPN. Not mapping office printers" sleep 2 goto drives endif
Would this work??
|
Top
|
|
|
|
#149619 - 2005-10-11 07:24 AM
Re: If instr(@ipaddress) ???
|
MarcD
Fresh Scripter
Registered: 2005-10-06
Posts: 7
|
Oh the spaces... Looks like I got it working!
|
Top
|
|
|
|
#149621 - 2005-10-11 07:58 AM
Re: If instr(@ipaddress) ???
|
MarcD
Fresh Scripter
Registered: 2005-10-06
Posts: 7
|
Quote:
The SLEEP statements also don't look like their really needed.
Just for testing
Quote:
The usage of GOTO is frowned upon.
Will see if I can change it... Thanks. Why is this frowned upon?
Quote:
Dimming your variables is also recommended.
Have you got an example?
Edited by MarcD (2005-10-11 08:03 AM)
|
Top
|
|
|
|
#149624 - 2005-10-25 09:39 PM
Re: If instr(@ipaddress) ???
|
sixdoubleo
Starting to like KiXtart
Registered: 2004-02-06
Posts: 118
Loc: California, US
|
I'm SURE there is a UDF to clean up the IP address...or even a way to strip spaces from a string elegantly, but I usually do something like this just so I'm comparing apples to apples...
$IP = @IPADDRESS0 $IP = Trim(Substr($IP,1,3))+"."+Trim(Substr($IP,5,3))+"."+Trim(Substr($IP,9,3))+"."+Trim(Substr($IP,13,3))
|
Top
|
|
|
|
#149625 - 2005-10-26 01:30 AM
Re: If instr(@ipaddress) ???
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Code:
Break On Dim $SO $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $SO=SetOption('NoMacrosInStrings','On')
Dim $IP $IP=Join(Split(@IPADDRESS0,' '),'') 'My IP is: ' + $IP ? 'My IP without blank removal: ' + @IPADDRESS0 ?
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 382 anonymous users online.
|
|
|