Page 1 of 1 1
Topic Options
#45399 - 2003-09-10 10:15 AM Ip value
Johan van Huyssteen_dup1 Offline
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 Offline
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 Offline
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
#45402 - 2003-09-10 11:53 AM Re: Ip value
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Splitting the IP’s at the dot so that you get 4 separate pieces and put these is 4 separate variables and doing the same for the second IP.
Then you will have something like this:

$IPa1 will be 172
$IPa2 will be 26
$IPa3 will be 181
$IPa4 will be 34

$IPb1 will be 172
$IPb2 will be 26
$IPb3 will be 181
$IPb4 will be 152

You can then compare $IPa1 to $IPb1 if this is the same continue with a compare of $IPa2 to $IPb2, etc…. until you find a difference and should do some script stuff.
I think this would be more reliable.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#45403 - 2003-09-11 12:02 AM Re: Ip value
Richard H. Administrator Offline
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 Offline
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
#45405 - 2003-09-11 12:10 AM Re: Ip value
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
r2d2, we already have subnet calculation routines in UDF lib and in an KiXgolf tournament.

anyway, it is not a bit more reliable as the above code is about bullet proof.
_________________________
!

download KiXnet

Top
#45406 - 2003-09-11 12:39 AM Re: Ip value
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
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.

So I think splitting the IP and comparing only pure numbers would be more reliable then the code posted by Johan.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#45407 - 2003-09-11 12:50 AM Re: Ip value
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, the compare of numbers and strings is similar...
kinda.
IP is actually string.
and comparing them like richard did, works a charm.

anyway, I would need to ask jens about having the golfed UDF being strict enough according to strandards to be posted in UDF lib.
current calculation UDFs are rather long and splitted.
_________________________
!

download KiXnet

Top
#45408 - 2003-09-10 01:12 PM Re: Ip value
Richard H. Administrator Offline
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
#45409 - 2003-09-10 02:15 PM Re: Ip value
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Thanx learned something today and should read better.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#45410 - 2003-09-11 07:52 AM Re: Ip value
Johan van Huyssteen_dup1 Offline
Fresh Scripter

Registered: 2003-08-28
Posts: 22
Loc: RSA
Thanks guys for all the help !!!!
Top
#45411 - 2003-09-17 08:17 PM Re: Ip value
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See also the FAQ Forum under TCP/IP Primer, Part I - IP Addresses
_________________________
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 2175 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

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