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.
You can remotely execute the command hostname command on these machines to acquire the Hostname
Query machine for hostname