added support for resolving IP addresses to domain when has a PTR record
authorRichard Penman
Thu, 02 Jun 2016 13:56:11 -0700
changeset 86 d6fcfa5acc7b
parent 85 0b098688af21
child 89 0b2e70f3f537
added support for resolving IP addresses to domain when has a PTR record
whois/__init__.py
--- a/whois/__init__.py	Thu Jun 02 13:37:33 2016 -0700
+++ b/whois/__init__.py	Thu Jun 02 13:56:11 2016 -0700
@@ -19,6 +19,12 @@
     ip_match = re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", url)
     if ip_match:
         domain = url
+        try:
+            result = socket.gethostbyaddr(url)
+        except socket.herror as e:
+            pass
+        else:
+            domain = result[0]
     else:
         domain = extract_domain(url)
     if command: