Commit 92106a9a by William Tisäter

Make simplified ip2long method work with Python 3.x

parent 72430d4a
...@@ -20,11 +20,8 @@ You should have received a copy of the GNU Lesser General Public License ...@@ -20,11 +20,8 @@ You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>. along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
""" """
import struct
import socket import socket
from array import array import binascii
from pygeoip.const import PY3
def ip2long(ip): def ip2long(ip):
...@@ -34,8 +31,6 @@ def ip2long(ip): ...@@ -34,8 +31,6 @@ def ip2long(ip):
@type ip: str @type ip: str
""" """
try: try:
return int(socket.inet_aton(ip).encode('hex'), 16) return int(binascii.hexlify(socket.inet_aton(ip)), 16)
except socket.error: except socket.error:
return int(socket.inet_pton(socket.AF_INET6, ip).encode('hex'), 16) return int(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)), 16)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment