Compare commits

...

3 Commits

Author SHA1 Message Date
Eli Ribble d577928b3a Respond with additional data so the client knows we interpreted things. 2024-08-21 14:22:47 -07:00
Eli Ribble 71a3076f99 Add not-working IP scan
This came from a bad LLM. Needs cleanup.
2024-08-21 14:22:31 -07:00
Eli Ribble a53f2205bf Fix logging setup.
I misspelled "getLogger"
2024-08-21 14:22:14 -07:00
1 changed files with 21 additions and 4 deletions

View File

@ -3,15 +3,32 @@ import argparse
import logging import logging
import socket import socket
LOGGER = logging.Logger(__name__) LOGGER = logging.getLogger(__name__)
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("host", help="The IPv6 address of the host to connect to.") parser.add_argument("--address", help="The IPv6 address to bind")
parser.add_argument("--port", "-p", default=50007, help="The port to connect to.") parser.add_argument("--port", "-p", default=50007, help="The port to connect to.")
parser.add_argument("--verbose", action="store_true", help="Verbose logging")
args = parser.parse_args() args = parser.parse_args()
addresses = [addr for addr in socket.getaddrinfo(host=args.host, port=args.port, family=socket.AF_INET6, type=socket.SOCK_STREAM, proto=0, flags=0)] logging.basicConfig(
format="%(asctime)s %(message)s",
level=logging.DEBUG if args.verbose else logging.INFO,
)
hostname = socket.gethostname()
addresses = []
for interface in socket.if_nameindex():
interface_name = interface[1]
LOGGER.debug("Found interface %s", interface_name)
try:
addrs = socket.getaddrinfo(host=hostname, port=80, family=socket.AF_INET6)
for addr in addrs:
addresses.append((interface_name, addr[4][0]))
except socket.gaierror:
LOGGER.info("Interfare '%s' has no IPv6 addresses", interface_name)
addresses = [addr for addr in socket.getaddrinfo(host=args.address, port=args.port, family=socket.AF_INET6, type=socket.SOCK_STREAM, proto=0, flags=0)]
if not addresses: if not addresses:
raise ValueError("Couldn't find ipv6 address for source %s" % source_ip) raise ValueError("Couldn't find ipv6 address for source %s" % source_ip)
if len(addresses) > 1: if len(addresses) > 1:
@ -40,7 +57,7 @@ def bind_socket(family, type_, proto, canonname, sockaddr):
while True: while True:
data = conn.recv(1024) data = conn.recv(1024)
if not data: break if not data: break
conn.send(data) conn.send(("Hey " + data.decode("UTF-8").encode("UTF-8"))
if __name__ == "__main__": if __name__ == "__main__":
main() main()