From bbf997eafaa3f40cc2278bd784636b77b6b716c5 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 27 Mar 2014 21:48:02 +0200 Subject: iploc: Optimize IP address parsing. Change-Id: Ieeac354aeee0ed10b8732b19183aa0320caac07a --- iploc.py | 4 ++-- 1 file 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 -- cgit v1.2.3