|
@ -31,7 +31,7 @@ import asyncio |
|
|
import socket |
|
|
import socket |
|
|
from typing import Tuple, Union, List, TYPE_CHECKING, Optional, Set, NamedTuple |
|
|
from typing import Tuple, Union, List, TYPE_CHECKING, Optional, Set, NamedTuple |
|
|
from collections import defaultdict |
|
|
from collections import defaultdict |
|
|
from ipaddress import IPv4Network, IPv6Network, ip_address, IPv6Address |
|
|
from ipaddress import IPv4Network, IPv6Network, ip_address, IPv6Address, IPv4Address |
|
|
import itertools |
|
|
import itertools |
|
|
import logging |
|
|
import logging |
|
|
import hashlib |
|
|
import hashlib |
|
@ -794,11 +794,13 @@ class Interface(Logger): |
|
|
if self.is_tor(): |
|
|
if self.is_tor(): |
|
|
return BUCKET_NAME_OF_ONION_SERVERS |
|
|
return BUCKET_NAME_OF_ONION_SERVERS |
|
|
try: |
|
|
try: |
|
|
ip_addr = ip_address(self.ip_addr()) |
|
|
ip_addr = ip_address(self.ip_addr()) # type: Union[IPv4Address, IPv6Address] |
|
|
except ValueError: |
|
|
except ValueError: |
|
|
return '' |
|
|
return '' |
|
|
if not ip_addr: |
|
|
if not ip_addr: |
|
|
return '' |
|
|
return '' |
|
|
|
|
|
if ip_addr.is_loopback: # localhost is exempt |
|
|
|
|
|
return '' |
|
|
if ip_addr.version == 4: |
|
|
if ip_addr.version == 4: |
|
|
slash16 = IPv4Network(ip_addr).supernet(prefixlen_diff=32-16) |
|
|
slash16 = IPv4Network(ip_addr).supernet(prefixlen_diff=32-16) |
|
|
return str(slash16) |
|
|
return str(slash16) |
|
|