Are there any existing libraries to parse a string as an ipv4 or ipv6 address, or at least identify whether a string is an IP address (of either sort)?
For IPv4, you can use
socket.inet_aton(some_string)
If it throws an exception, some_string is not a valid ip address
some_string
For IPv6, you can use:
socket.inet_pton(socket.AF_INET6, some_string)
Again, it throws an exception, if some_string is not a valid address.