When you ask gethostbyname() "Is this a valid host name?" what you are doing is sending a query to the Domain Name System asking "Is there a mapping between this Human Readable string and an IP address?" DNS responds either 'yes, and here it is' or 'no, such a mapping does not exist'.

When you ask "Is this a valid IP address", the form of the string is checked, and if it matches the specification in the RFC (four strings separated by periods; each string numeric and in the range 0 -- 255), then the the IP address is valid.

If you want to know whether a valid IP address is actually in use, then you will have to try it out. The usual tool is ping() with an appropriate time-out; or traceroute() if you want to know the path information as well.

Update -- straightened out the syntax in the second paragraph.

----
I Go Back to Sleep, Now.

OGB


In reply to Re: To know the existence of an ip address by Old_Gray_Bear
in thread To know the existence of an ip address by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.