On Tuesday, April 30, 2002, at 05:51 , David Ulevitch wrote:
[..]
> 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?
how about:
the premise is that 'hostnames' in your example are what
we would call fully qualified 'network names' - I of course
do not deal with resolving the 'bob' - but that would be
where you would want to do the
perldoc -f gethostbyname
to check if these are valid hostnames ...
### #!/usr/bin/perl -w
### use strict;
###
### # ipaddr_or_hostname.pl- is for
###
### my @whatAreThese = qw/ 3.14159.com 192.168.2.1 wetware.com bob/;
### my $type;
###
### foreach my $nameserver (@whatAreThese) {
### if ( $nameserver =~ m/\.[a-zA-Z]+$/ ) {
### $type = "possible Hostname";
### }elsif ($nameserver =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/){
### $type = "possible IP_ADDR";
### }else{
### $type = "UNK"
### }
###
### print "It appears that $nameserver is a $type\n";
### }
###
### =cut
### which gens:
### It appears that 3.14159.com is a possible Hostname
### It appears that 192.168.2.1 is a possible IP_ADDR
### It appears that wetware.com is a possible Hostname
### It appears that bob is a UNK
### =cut
###
### # end of the world as I knew it [EMAIL PROTECTED] all rights reserved
### # ginned On 30-Apr-02
### #
###
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]