6

How does the python function socket.gethostbyname work?

Specifically, how does python obtain the ipv4 address from the fully qualified domain name?

category
  • 2,113
  • 2
  • 22
  • 46
  • 1
    CPython is open-source, why don't you check it yourself: [`socketmodule.c`](https://github.com/python/cpython/blob/67e1478dba6efe60b8e1890192014b8b06dd6bd9/Modules/socketmodule.c) - `socket_gethostbyname` function, then follow the thread where it takes you as it depends on the underlying platform. – zwer Jul 26 '17 at 13:58
  • 6
    It gets translated into a gethostbyname system call, which first checks the hosts file and if the name's not found there it queries a DNS server. See https://stackoverflow.com/questions/20284094/how-gethostbyname-or-getnameinfo-work-in-background – PM 2Ring Jul 26 '17 at 14:01
  • 1
    Thanks, that was the information I needed for a related issue - please may you post that as an answer? – category Jul 27 '17 at 07:58

0 Answers0