views:

47

answers:

3

I want to query an IP to get its hostname. What is the standard port for this ? Could it be port 101 listed under "hostnames" in /etc/services ?

+2  A: 

Most of the "well known ports" found in /etc/services are remnants of historic implementations -- implementations of these "historic protocols" are no longer in use.

The port 101 you found is commented "NIC Host Name Server". I found that RFC 811 and RFC953 describe the protocol served on port 101. Most interesting to note is that the only implementation at the time of RFC 811 (1982) was running on a particular machine at SRI International. The "port 101 protocol" is not a service that you will find on the Internet in the modern time.

The only service I can think of which is designed to provide information like you need is SNMP, and there is no guarantee you will either find an SNMP service running or that you will know the access keyword required ("community name") to see the remote hostname via the SNMP service.

Many specific implementations of services respond with the hostname, for example:

telnet alias.machine.net 25
220 realname.machine.net ESMTP Postfix (Debian/GNU)

Edit: A few other answers are suggesting you look into the DNS port. DNS (Domain Name System) is not really what you asked for. If you do want to use a DNS lookup, however, check into the gethostbyaddr() function available from C under Windows, MacBSD and Linux.

Heath Hunnicutt
A: 

well dns runs on port 53

Anon
+2  A: 

UDP port 101 used to provide the 'hostname' service, but the original RFC (RFC811) is obsoleted by RFC953, and RFC953 is marked 'historic'.

These days, you would consult the DNS (Domain Name System), which has many other relevant RFCs listed as updating it. And you would normally use the appropriate library functions for the language you are using to consult the DNS (one issue being what is the IP address of the DNS server you should consult).

In both these cases (hostname and DNS), you consulted a machine other than the one with the specific IP address you are interested in. It is not clear from your question whether you expect to ask the host with the interesting IP address what its name is, or whether you are expecting to ask another machine the question. In practice, you will end up asking other machines - the DNS server(s).

Jonathan Leffler