mirror of
https://github.com/progval/irctest.git
synced 2025-04-07 07:49:52 +00:00
Make find_hostname_and_port its own function
So it can be used to generate multiple ports, which will be needed to link services.
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import datetime
|
||||
import re
|
||||
import secrets
|
||||
from typing import Dict
|
||||
import socket
|
||||
from typing import Dict, Tuple
|
||||
|
||||
# thanks jess!
|
||||
IRCV3_FORMAT_STRFTIME = "%Y-%m-%dT%H:%M:%S.%f%z"
|
||||
@ -15,6 +16,15 @@ def random_name(base: str) -> str:
|
||||
return base + "-" + secrets.token_hex(8)
|
||||
|
||||
|
||||
def find_hostname_and_port() -> Tuple[str, int]:
|
||||
"""Find available hostname/port to listen on."""
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.bind(("", 0))
|
||||
(hostname, port) = s.getsockname()
|
||||
s.close()
|
||||
return (hostname, port)
|
||||
|
||||
|
||||
"""
|
||||
Stolen from supybot:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user