Python resolves hostname with IPv6 address

I wonder if there is a way to use python to resolve the host name, which is resolved only in ipv6 and / or for the host name, which resolves both in ipv4 and ipv6?

socket.gethostbyname() and socket.gethostbyname_ex() do not work for ipv6 resolution.

The fake way to do this is to run a real linux host command and analyze the results. Is there a better way to do this?

Thanks,

+4
source share
1 answer

socket.getaddrinfo supports IPv6. You just need to set family to AF_INET6 .

 socket.getaddrinfo("example.com", None, socket.AF_INET6) 
+11
source

Source: https://habr.com/ru/post/1468846/


All Articles