mirror of https://github.com/CIRCL/url-abuse
fix: saner way to test if a string is an IP
parent
5df3add8de
commit
ee30ff730f
|
@ -10,6 +10,7 @@ import json
|
||||||
import redis
|
import redis
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from .helpers import get_socket_path
|
from .helpers import get_socket_path
|
||||||
|
import ipaddress
|
||||||
|
|
||||||
|
|
||||||
from pyfaup.faup import Faup
|
from pyfaup.faup import Faup
|
||||||
|
@ -128,24 +129,11 @@ def is_valid_url(url):
|
||||||
|
|
||||||
|
|
||||||
def is_ip(host):
|
def is_ip(host):
|
||||||
if isinstance(host, bytes):
|
try:
|
||||||
to_search = b':'
|
ipaddress.ip_address(host)
|
||||||
else:
|
return True
|
||||||
to_search = ':'
|
except ValueError:
|
||||||
|
return False
|
||||||
if to_search in host:
|
|
||||||
try:
|
|
||||||
socket.inet_pton(socket.AF_INET6, host)
|
|
||||||
return True
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
socket.inet_aton(host)
|
|
||||||
return True
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def try_resolve(fex, url):
|
def try_resolve(fex, url):
|
||||||
|
|
Loading…
Reference in New Issue