an ip address should have 3 dot and 2 (IPv4) so ii you check for the number of dot you have you will remove some false guess
Pierre >From: drieux <[EMAIL PROTECTED]> >Reply-To: [EMAIL PROTECTED] >To: [EMAIL PROTECTED] >Subject: Re: checking if domain or IP address >Date: Tue, 30 Apr 2002 18:07:21 -0700 > > >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] > _________________________________________________________________ Join the world’s largest e-mail service with MSN Hotmail. http://www.hotmail.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]