Add not-working IP scan

This came from a bad LLM. Needs cleanup.
This commit is contained in:
Eli Ribble 2024-08-21 14:22:31 -07:00
parent a53f2205bf
commit 71a3076f99
1 changed files with 18 additions and 2 deletions

View File

@ -7,12 +7,28 @@ 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") 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: