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)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, there is
ipaddrmodule, that can you help to check if a string is a IPv4/IPv6 address, and to detect its version.But this is not a standard module, so it is not always possible to use it.
You also try using the standard
socketmodule:For IPv6 addresses you must use
socket.inet_pton(socket.AF_INET6, address).I also want to note, that
inet_atonwill try to convert (and really convert it) addresses like10,127and so on, which do not look like IP addresses.