Skip to content

Instantly share code, notes, and snippets.

@mjseeley
Created November 6, 2014 20:43
Show Gist options
  • Save mjseeley/af0a75ac8f7db8a15b4e to your computer and use it in GitHub Desktop.
Save mjseeley/af0a75ac8f7db8a15b4e to your computer and use it in GitHub Desktop.
def get_rdns(ip)
import socket
# Function/arguments: get_rdns(ip)
# Description: Perform a reverse DNS query for the passed-in IP address.
# Returns: String: the reverse DNS name, or ''.
def get_rdns(ip):
try:
result = socket.gethostbyaddr(ip)[0]
except socket.herror:
# print 'Unable to get rDNS for', ip
result = ip
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment