Page 1 of 1 1
Topic Options
#139665 - 2005-05-12 04:20 PM Translate please
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Hi out there gurus,

Could u translate this into kix code?

If 192.168.0.32 is between 192.168.0.30 to 192.168.0.128
print segment1
else
print external

_________________________
I will always look out from behind these eyes...

Top
#139666 - 2005-05-12 05:04 PM Re: Translate please
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
... or mayby this:

$IP = "192.168.0.32"
$BIP = "192.168.0.30"
$UIP = "192.168.0.128"

If $IP => $BIP and $IP =< $UIP
? segment1
else
? external
endif


Edited by JazzM (2005-05-12 05:14 PM)
_________________________
I will always look out from behind these eyes...

Top
#139667 - 2005-05-12 06:01 PM Re: Translate please
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
there are a number of IP Subnetting UDF's...

and a 3 very nice posts in the FAQ that deal with IP and ip subnetting.
TCP/IP Primer, Part I - IP Addresses
TCP/IP Primer, Part II - Classless Inter-Domain Routing (CIDR)
TCP/IP Primer, Part III - IP Addresses and KiXtart

Top
#139668 - 2005-05-18 02:03 PM Re: Translate please
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
:-(

I check the posts (very nice indeed), but I couldnt figure out how to solve my problem in a simple proper way...

The code below works if the sub segment is /24 (256 IP),
but doesnt "work" if the sub segment is /25 (128 IP) !?!
...and why is that?

If $IP > ""

Select

Case $IP > "192.168.0.1" AND $IP < "192.168.0.255"
? "IP found in Sub1"
Case $IP > "192.168.1.1" AND $IP < "192.168.1.255"
? "IP found in Sub2"

Case $IP > "192.168.10.1" AND $IP < "192.168.10.128" ; <----
? "IP found in Sub3"
Case $IP > "192.168.10.128" AND $IP < "192.168.10.255" ; <----
? "IP found in Sub33"

EndSelect
else
? 'IP Map Not Available!'
EndIf


... getting mad ¤½#"!
_________________________
I will always look out from behind these eyes...

Top
#139669 - 2005-05-18 02:57 PM Re: Translate please
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I personaly would use Richard's IpDecimal() UDF for this stuff.

and the following code.

Code:

$IP=EnumIPInfo(0,0)
$Mask=EnumIPInfo(0,1)

Select
case IPDecimal(IPDecimal($IP) & IPDecimal($Mask)) = "192.168.1.0"
;you are in the 192.168.1.0 subnet

case IPDecimal(IPDecimal($IP) & IPDecimal($Mask)) = "192.168.1.2"
;you are in the 192.168.1.1 subnet

case IPDecimal(IPDecimal($IP) & IPDecimal($Mask)) = "192.168.1.3"
;you are in the 192.168.1.2 subnet

case IPDecimal(IPDecimal($IP) & IPDecimal($Mask)) = "192.168.1.4"
;you are in the 192.168.1.3 subnet
endselect


Top
#139670 - 2005-05-18 03:01 PM Re: Translate please
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Think your falling victim to the same thing in this thread:

Comparing Strings

Anyways, think you need to build-in some form of IP-sensitive compare function ... here is a quick version ...

This UDF compares two IP's ... it returns -1 if IP1 is < IP2, returns 1 if IP1 is greater than IP2, and 0 (zero) if they are the same. This UDF is a quick-hitter so not sure if I covered all the bases. Use it like this:

Code:

If CompareIP("1.2.3.4","1.0.3.4") = 1
?"IP1 is greater than IP2"
Endif



And the code:

Code:

Function CompareIP($ip1,$ip2)

dim $aip1, $aip2, $i

$aip1 = split($ip1,".")
$aip2 = split($ip2,".")

$CompareIP = 0

if ubound($aip1) <> ubound($aip2)
return
endif

for $i = 0 to ubound($aip1)

if val($aip1[$i]) > val($aip2[$i])
$CompareIP = 1
return
endif

if val($aip1[$i]) < val($aip2[$i])
$CompareIP = -1
return
endif

next

EndFunction


Top
#139671 - 2005-05-18 03:12 PM Re: Translate please
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There is a reason why KiX pads out the IP. It is so that string compares would work. By stripping out the spaces, you defeat string compares.

That said, string compares are a lousy way to go. Either use one of the many UDFs out there or else simply break up the IP into octets and convert then to numeric with Val() so that proper compares can be performed.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#139672 - 2005-05-18 03:25 PM Re: Translate please
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Is this comment directed to me or Jazzy ?
Top
#139673 - 2005-05-18 05:24 PM Re: Translate please
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Both (Everyone)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#139674 - 2005-05-18 06:20 PM Re: Translate please
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
...'ba' is greater than 'a'... hmm, so thats what its all about...

However boys, Im sorry to say, but I cannot make the damn thing work for my propose...
Need to restate:

A singel IP is predefined: $IP (some client IP)
There are, say 10 subnets with diffrent masks.
Some subnets have 256 IP some other 128 IP(diffrent masks)
The subnets are predefined too.

So no comparing singel IPs or calculating sunbet masks are needed.

Just print some txt if the IP is between to given IP ranges.
The IP range could be 1-256, or 1-128, or 128-256 and so on.

But stil not works, my damn code
_________________________
I will always look out from behind these eyes...

Top
#139675 - 2005-05-18 06:45 PM Re: Translate please
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
JazzM,

the code that i posted can handle differnet subnets...

here is a simple example.

Code:

$myipaddress = "10.10.210.99"
$mySubnetmask = "255.255.128.0"

? "My subnet is " + IPDecimal(IPDecimal($myipaddress)&IPDecimal($mySubnetmask))




and when you run the script you get..

Code:

My subnet is 10.10.128.0


Top
#139676 - 2005-05-19 04:31 AM Re: Translate please
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Please see IsInSubnet()
Code:

$ip='10.10.10.1'
$networkid='10.10.10.0'
$subnetmask='255.255.255.0'
$answer = isinsubnet($ip,$networkid,$subnetmask)
? 'Error = '+@ERROR+ ' - '+@SERROR
? 'IsInSubnet = '+$answer
redim $networkid[2]
$ip='10.10.10.1'
$networkid[0]='10.10.10.0/24'
$networkid[1]='10.10.10.0/27'
$networkid[2]='10.10.0.0/255.255.0.0'
$answer = isinsubnet($ip,$networkid)
$answer = isinsubnet($ip,$networkid,,1)
$answer = isinsubnet($ip,$networkid,,2)

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

Top
#139677 - 2005-05-21 03:34 PM Re: Translate please
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Sorry my confusions, Bryce code works!
Now im happy

Thanx a lot all u great folks out there!
Cheers
_________________________
I will always look out from behind these eyes...

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
1 registered (Allen) and 1172 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.068 seconds in which 0.031 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