in reply to To know the existence of an ip address

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

  • Comment on Re: To know the existence of an ip address