root_builder = root_builder.public_key(root_public_key)
root_builder = root_builder.add_extension(
x509.SubjectAlternativeName(
- [x509.IPAddress(ipaddress.IPv4Address(addr))]
+ [x509.IPAddress(ipaddress.ip_address(addr))]
),
critical=False
)
def generate_cert(self, host: str, addr: str) -> Tuple[str, str]:
have_ip = True
try:
- ip = x509.IPAddress(ipaddress.IPv4Address(addr))
+ ip = x509.IPAddress(ipaddress.ip_address(addr))
except Exception:
- try:
- ip = x509.IPAddress(ipaddress.IPv6Address(addr))
- except Exception:
- have_ip = False
+ have_ip = False
private_key = rsa.generate_private_key(
public_exponent=65537, key_size=4096, backend=default_backend())
import time
import logging
import sys
+from ipaddress import ip_address
from threading import Lock, Condition, Event
from typing import no_type_check, NewType
import urllib
If no exception is raised, the port can be assumed available
"""
try:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ ip_version = ip_address(addr).version
+ addr_family = socket.AF_INET if ip_version == 4 else socket.AF_INET6
+ sock = socket.socket(addr_family, socket.SOCK_STREAM)
sock.bind((addr, port))
sock.close()
except socket.error as e: