Skip to content

Instantly share code, notes, and snippets.

@tomasfejfar
Created August 22, 2013 15:29
Show Gist options
  • Select an option

  • Save tomasfejfar/6308726 to your computer and use it in GitHub Desktop.

Select an option

Save tomasfejfar/6308726 to your computer and use it in GitHub Desktop.
hostname resolver
import socket
def resolve(hostname):
return socket.gethostbyname(hostname)
@yermulnik
Copy link
Copy Markdown

socket.gethostbyname would return only the first resolved ip-address despite the fact that host may have more than one ip-address. To get all of the ip-addresses I'd recommend to use socket.gethostbyname_ex. E.g.: return socket.gethostbyname_ex(hostname)[2] - would return a list of all ip-addresses that the host resolves to.

@aholbreich
Copy link
Copy Markdown

I is possible to integrate it to asible teplates?

@redbaron4
Copy link
Copy Markdown

socket.getaddrinfo may be a better choice ever since GHOST vulnerability was disclosed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment