Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python resolve a host name with IPv6 address

Tags:

python

ipv6

dns

I wonder if there is a way to use python to resolve a hostname that resolves only in ipv6 and/or for a hostname that resolves both in ipv4 and ipv6?

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

A dummy way to do that is to run actual linux host command and parse the results. Is there any better way to do that?

Thanks,

like image 607
Amir Avatar asked Mar 12 '13 22:03

Amir


1 Answers

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

socket.getaddrinfo("example.com", None, socket.AF_INET6)
like image 94
John Colanduoni Avatar answered Sep 25 '22 20:09

John Colanduoni