If your IP address is "8.8.8.8", you can get the hostname using the following code.
import socket ip = "8.8.8.8" hostname = socket.gethostbyaddr(ip) print(hostname) print(hostname[0])
('google-public-dns-a.google.com', [], ['8.8.8.8']) google-public-dns-a.google.com
Comment here