Ben Morrow wrote:
>
> Quoth Tuxedo <>:
> > This may be a vague question but which perl network tools or procedures
> > are good to determine if a hostname or IP exist and that is suitable for
> > a cgi request that allows user-input of any URL string?
>
> The core gethostbyname function will tell you if a given name has an
> address in the DNS. The Net:
NS module will let you make more specific
> queries if you need to.
Thanks for the advise, most helpful!
I'm not sure what I need yet but before making DNS requests I think would
be a good idea to validate the URL input.
I read that gethostbyname is not IPv6 compatible which may run into trouble:
http://stackoverflow.com/questions/1...-when-given-ip
The Net:

NS tools look interesting and in combination with Net::LibIDN it
appears to support IDNs.
I'm not quite sure how to validate a URI and I guess there is no simple way
to do so by existing core modules.
To cover a growing number of IDNs, IDNsNet-IDN-Encode-2.003 seem to be a
good tool in converting IDNs to their ASCII representations:
http://search.cpan.org/~cfaerber/Net.../IDN/Encode.pm
I will test Data::Validate::URI first, which require various non-core
modules, namely Data::Validate::IP, Net:

omain::TLD as well as
Net::Netmask.
> Determining if an IP exists is harder, since you can't in general assume
> any given IP will respond to any particular protocol. Net:
ing would be
> a start, but a lot of sites block external pings (even though they
> shouldn't).
>
> > An HTTP status code may return any response, such as 200, 404 or
> > something else. Whatever the response may be, as long as there is an
> > actual response, DNS record or server existing, a subroutine should
> > return true. If however the hostname or IP is non-existing, or if the
> > user input has a wrong syntax, the perl code should return false.
>
> Oh, you didn't say 'HTTP'. If you want to check an HTTP server exists,
> you can either just open a connection to port 80 with IO::Socket::INET
> (and close it again without sending a response), or send a HEAD request
> with LWP::Simple.
>
> You should be aware that some sites may consider this sort of behaviour
> to be port-scanning, and may take action to prevent you from doing it.
> In particular, you should be very careful not to probe any particular
> server too often, as that would almost certainly be considered abuse.
Thanks for the words of warning.
Tuxedo
>
> Ben
>