Add IPv6 to tests

This commit is contained in:
Grégory Soutadé 2016-02-17 18:15:04 +01:00
parent 2456039df1
commit 501e5b2acf
2 changed files with 7 additions and 4 deletions

View File

@ -46,15 +46,16 @@ class IPToGeo(object):
5 : 'Unsupported IP version',
6 : 'IP not found'}
def __init__(self, remote_addr='127.0.0.1', remote_port=53333, timeout=None):
def __init__(self, remote_addr='127.0.0.1', remote_port=53333, timeout=None, family=socket.AF_INET):
self._remote_addr = remote_addr
self._remote_port = remote_port
self._timeout = timeout
self._family = family
self._create_socket()
def _create_socket(self):
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._socket = socket.socket(self._family, socket.SOCK_STREAM)
if not self._timeout is None:
self._socket.settimeout(self._timeout)
self._socket.connect((self._remote_addr, self._remote_port))

View File

@ -2,12 +2,14 @@
# -*- coding: utf-8
import os
import sys
import socket
from iptogeo import IPToGeo, IPToGeoException
TIMEOUT = None
# TIMEOUT = 5.0
iptogeo = IPToGeo(timeout=TIMEOUT)
iptogeo = IPToGeo(timeout=TIMEOUT, family=socket.AF_INET6, remote_addr='::1')
def get_random_ip_v4():
ip = '%d.%d.%d.%d' % \