1

I want to be able to scan a network of servers and match IP addresses to hostnames.

I saw a lot of questions about this (with a lot of down votes), but none are exactly what I'm looking for.

So I've tried python's socket library socket.gethostbyaddr(ip). But this only returns results if I have a DNS setup or the IP-to-host mapping is in my hosts file.

I want to be able to ask a machine for their hostname, rather than querying DNS.

How can a query a Linux machine for their hostname?

Preferably using python or bash, but other ways are good too.

1

1 Answer 1

3

You can remotely execute the command hostname command on these machines to acquire the Hostname

Sign up to request clarification or add additional context in comments.

6 Comments

That sounds perfect, can you elaborate please?
since your host are Linux based machines they support a command called hostname which will return the hostname of the machines.
Is there a way to execute that command without logging in to the machine?
You either run it over ssh (which is logging in), or install a server (a web server, perhaps?) which runs something that returns the hostname.
@dan08 ssh machinename hostname. You need key based authentication.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.