>   I have a small perl script which checks to see if input is a
>   hostname or an IP address before writing it to a file.
> 
>   I was just checking to see if the first char was a number or a
>   digit but there are some cases where a hostname can start with a
>   number. (like 3.14159.com for example)
> 
>   So the question is, if I have a variable like $nameserver
>   how can I test to see if it's a hostname or an IP?

        Here's one way to do it. It's not fool proof since it doesn't
validate legal IP/Domain formats, but it's a starting point.

@array = split(/\./,$nameserver);
$string = join('',@array);
if ($string =~ /\D/) {
        $IP = 'no';
} else {
        $IP = 'yes';
}

        Another simple way would be to check for a TLD extension.

@array = split(/\./,$nameserver);
if (@array[-1] =~ /\d/) {
        $IP = 'yes';
} else {
        $IP = 'no';
}

        Validating Domains and IP's is alot more intensive, because
there are numerous (and occasionally changing) factors to check for.

===================
 Shaun Fryer
===================
 London Webmasters
 http://LWEB.NET
 PH:  519-858-9660
 FX:  519-858-9024
===================



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to