Reputation: 1750
Is there a way(a C API?), using which I can get the hostname of a remote server. Something like gethostname() but having an IP address as an argument.
I know about getnameinfo() and getaddrinfo(), however I don't want the hostname used in the DNS server. I want the hostname which you get when you use the hostname command in linux. I have a feeling that it might be impossible to do without knowing the login credentials of that remote server but I'm not sure about it.
Upvotes: 0
Views: 507
Reputation: 30709
Although you can query DNS for hostnames, there's no standard protocol to ask a machine (an interface, really) what it calls itself (if it does even have a name for itself - that's not mandatory).
You'd need to implement and deploy a simple server program onto all the hosts you're interested in (it could be something as simple as adding a line to /etc/inetd.conf
to run /bin/hostname
if it's a Unix-like system), and a client library to access it.
Upvotes: 1