aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <paul.sokolovsky@linaro.org>2014-03-27 21:48:02 +0200
committerPaul Sokolovsky <paul.sokolovsky@linaro.org>2014-03-28 01:37:28 +0200
commitbbf997eafaa3f40cc2278bd784636b77b6b716c5 (patch)
treef078b19d4229a86cc5d8a6aa0007377b4f97ab27
parentfb5683f0ebbe6e67c353518366bac81848c6c9b9 (diff)
iploc: Optimize IP address parsing.
Change-Id: Ieeac354aeee0ed10b8732b19183aa0320caac07a
-rw-r--r--iploc.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/iploc.py b/iploc.py
index b70c203..3b6085a 100644
--- a/iploc.py
+++ b/iploc.py
@@ -9,6 +9,7 @@ import struct
import sys
import os
import optparse
+import socket
from bsddb3 import db
@@ -49,10 +50,9 @@ temp_user = ""
def get_reverse_dns(ip_address):
# XXX: this works only with IPv4 addresses (because dnshistory works only with IPv4)
- octets = str(ip_address).split('.')
# The keys in the the reverse DNS db are stored as a char encoded string
# made from the single octet of the IP address.
- key = ''.join(chr(int(x)) for x in octets)
+ key = socket.inet_aton(ip_address)
value = REVERSE_DNS_DB.get(key)
struct_sz = struct.calcsize("li")
assert len(value) > struct_sz