Add IPv6 to tests
This commit is contained in:
parent
2456039df1
commit
501e5b2acf
|
@ -46,15 +46,16 @@ class IPToGeo(object):
|
||||||
5 : 'Unsupported IP version',
|
5 : 'Unsupported IP version',
|
||||||
6 : 'IP not found'}
|
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_addr = remote_addr
|
||||||
self._remote_port = remote_port
|
self._remote_port = remote_port
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
|
self._family = family
|
||||||
|
|
||||||
self._create_socket()
|
self._create_socket()
|
||||||
|
|
||||||
def _create_socket(self):
|
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:
|
if not self._timeout is None:
|
||||||
self._socket.settimeout(self._timeout)
|
self._socket.settimeout(self._timeout)
|
||||||
self._socket.connect((self._remote_addr, self._remote_port))
|
self._socket.connect((self._remote_addr, self._remote_port))
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
# -*- coding: utf-8
|
# -*- coding: utf-8
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import socket
|
||||||
from iptogeo import IPToGeo, IPToGeoException
|
from iptogeo import IPToGeo, IPToGeoException
|
||||||
|
|
||||||
TIMEOUT = None
|
TIMEOUT = None
|
||||||
# TIMEOUT = 5.0
|
# TIMEOUT = 5.0
|
||||||
|
|
||||||
iptogeo = IPToGeo(timeout=TIMEOUT)
|
iptogeo = IPToGeo(timeout=TIMEOUT, family=socket.AF_INET6, remote_addr='::1')
|
||||||
|
|
||||||
def get_random_ip_v4():
|
def get_random_ip_v4():
|
||||||
ip = '%d.%d.%d.%d' % \
|
ip = '%d.%d.%d.%d' % \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user