[Pdns-users] PDNS-Admin features

Tullio Andreatta ML t.andreatta at troppoavanti.it
Mon Feb 11 18:30:46 CET 2008


Roger Libiez wrote:
> I wasn't actually referring to the formats the user types in, those will 
> obviously need to be checked too. I was referring to verifying that what 
> they entered is in fact a valid address. Take the example Wikipedia uses:
> 
> 2001:0db8:0000:0000:0000:0000:1428:57ab can be expressed as any of the 
> following:
> 
> 2001:0db8:0000:0000:0000:0000:1428:57ab
> 2001:0db8:0000:0000:0000::1428:57ab
> 2001:0db8:0:0:0:0:1428:57ab
> 2001:0db8:0:0::1428:57ab
> 2001:0db8::1428:57ab
> 2001:db8::1428:57ab
> 
> So if the user actually puts in 2001:0db8:0000:0000:0000:0000:1428:57ab 
> and we use this to see if it's a valid address:
> 
>     function is_valid_ip($ip)
>     {
>         return( $ip == inet_pton(inet_ntop($ip))) ? true : false;
>     }
> 

function is_valid_ip($ip) {
   if ($ip == inet_pton(inet_ntop($ip))) return true;
   $ip = preg_replace(array('/^0+/', '/:0+/'), array('', ':'), $ip);
   return ($ip == inet_pton(inet_ntop($ip)));
}



-- 
Tullio Andreatta
09:f9:11:02:9d:74:e3:5b:d8:41:56:c5:63:56:88:c0
45:5f:e1:04:22:ca:29:c4:93:3f:95:05:2b:79:2a:b2

Disclaimer: "Please treat this email message in a reasonable way, or we
     might get angry" ( http://www.goldmark.org/jeff/stupid-disclaimers )



More information about the Pdns-users mailing list