fixes for the @echarlie IPv6 patch (#160)
This commit is contained in:
parent
b1ebd1b605
commit
ef50b23f5b
1 changed files with 6 additions and 5 deletions
|
|
@ -11,7 +11,6 @@ from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
import socket
|
import socket
|
||||||
import requests
|
import requests
|
||||||
import geoip2.database
|
import geoip2.database
|
||||||
|
|
@ -36,13 +35,15 @@ def is_ip(ip_addr):
|
||||||
Check if `ip_addr` looks like an IP Address
|
Check if `ip_addr` looks like an IP Address
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip_addr) is None:
|
|
||||||
return False
|
|
||||||
try:
|
try:
|
||||||
socket.inet_aton(ip_addr)
|
socket.inet_pton(socket.AF_INET, ip_addr.encode("utf-8"))
|
||||||
return True
|
return True
|
||||||
except socket.error:
|
except socket.error:
|
||||||
return False
|
try:
|
||||||
|
socket.inet_pton(socket.AF_INET6, ip_addr.encode("utf-8"))
|
||||||
|
return True
|
||||||
|
except socket.error:
|
||||||
|
return False
|
||||||
|
|
||||||
def location_normalize(location):
|
def location_normalize(location):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue