#139666 - 2005-05-12 05:04 PM
Re: Translate please
|
JazzM
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
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
|
|
Top
|
|
|
|
#139669 - 2005-05-18 02:57 PM
Re: Translate please
|
Bryce
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
   
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
|
|
|
|
#139675 - 2005-05-18 06:45 PM
Re: Translate please
|
Bryce
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
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1172 anonymous users online.
|
|
|