I have a script that is given a bunch of local IPv4 addresses in a local network. I can get the hostnames of those IPs in Python2.7 via:
socket.gethostbyaddr(IP)
However, these hostnames (if resolved) return as something of the form:
hostname.local.companyname.com
The only piece of information I'm interested in with this value is hostname
. I would like to remove the local.companyname.com
domain name from the fully qualified hostname. I could find the aspects of all resolved hostnames in common and then remove them that way, but I'm wondering if there is there any way to directly query the local domain itself?
(edit: this is running on Ubuntu)