#45399 - 2003-09-10 10:15 AM
Ip value
|
Johan van Huyssteen_dup1
Fresh Scripter
Registered: 2003-08-28
Posts: 22
Loc: RSA
|
[Moderator (Sealeopard): Moved topic from 'Scripts' to 'Starters' forum due to lack of script in body]
I need a script that will verify if an ip is between to ip values or ip scope. eg.
172.25.16.34 172.25.16.80
if its true complete the script if its false exit [ 17. September 2003, 20:17: Message edited by: sealeopard ]
|
|
Top
|
|
|
|
#45400 - 2003-09-10 10:37 AM
Re: Ip value
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If you are trying to check whether the IP address is on a particular subnet, use one of the UDFs from the UDF forum - there are a few to choose from.
If you want to check whether the IP address is in a range which is not actually a subnet and the IP address is from @IPADDRESS0 then a simple string compare will work, just don't forget to include the spaces.
code:
If $sIPAddress >= "172. 25 16 34" AND $sIPAddress <= "172. 25. 16. 80" ; Do your stuff Else Exit 1 EndIf
[ 10. September 2003, 10:38: Message edited by: Richard H. ]
|
|
Top
|
|
|
|
#45401 - 2003-09-10 11:31 AM
Re: Ip value
|
Johan van Huyssteen_dup1
Fresh Scripter
Registered: 2003-08-28
Posts: 22
Loc: RSA
|
This is how I changed the code its working 100% thanks for the help in dutch "dit werk bedonnerd" "baie dankie"
If @IPADDRESS0 >= "172. 26.181. 34" AND @IPADDRESS0 <= "172. 26.181.152" "Do your stuff" ? Else Exit 1 EndIf sleep 10
|
|
Top
|
|
|
|
#45403 - 2003-09-11 12:02 AM
Re: Ip value
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
quote: I think this would be more reliable.
Do you? Why?
|
|
Top
|
|
|
|
#45404 - 2003-09-11 12:09 AM
Re: Ip value
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If you are concerned about comparing with spaces in the string, just replace them with zeroes:
code:
$sIPAddress=Join(Split(@ADDRESS0),"0") If $sIPAddress >= "172.025.016.034" AND $sIPAddress <= "172.025.016.080" ; Do your stuff Else Exit 1 EndIf
But it really shouldn't be necessary.
|
|
Top
|
|
|
|
#45408 - 2003-09-10 01:12 PM
Re: Ip value
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
quote: Haven't checked the UDF's but I always learned that a compare between numbers can only be done when the value contains only pure numbers so a compare between 10.10.0.1 and 10.10.4.5 would be unreliable.
A common misunderstanding. If you look at my first post you will see that I say "a simple string compare will work"
We are not comparing the numbers in the IP address, we are comparing the entire strings. Now, the strings happen to comprise numeric characters, "." and space characters but they are still strings.
You will only get a problem where the strings are of different length, because the comparison is left-to-right. The string returned by @IPADDRESSx has the octets space filled to justify them, which means that a string compare will work.
As an example, here is a string compare of IP addresses. The first one using the IP address in the form returned by @IPADDRESSx will work, the second one using non-justified values will fail:
code:
$sIPAddress=" 10. 0. 0. 50" If $sIPAddress > " 10. 0. 0. 9" "Test 1 works :)" ? Else "Test 1 fails :(" ? EndIf $sIPAddress="10.0.0.50" If $sIPAddress > "10.0.0.9" "Test 2 works :)" ? Else "Test 2 fails :(" ? EndIf
[edit] As a further example you can also compare dates in the same way, so the following examples will work fine:
code:
If @DATE > "2004/00/00" AND @DATE < "2004/99/99" "The year is 2004!" ? EndIf $sExpires="2010/08/11" If @DATE >= $sExpires "Sorry, the license has expired." ? EndIf
[/edit] [ 10. September 2003, 13:21: Message edited by: Richard H. ]
|
|
Top
|
|
|
|
#45410 - 2003-09-11 07:52 AM
Re: Ip value
|
Johan van Huyssteen_dup1
Fresh Scripter
Registered: 2003-08-28
Posts: 22
Loc: RSA
|
Thanks guys for all the help !!!!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2630 anonymous users online.
|
|
|