문제

I'm using gethostbyname function for DNS and IP addresses checking. However, it does not work well in this case:

>>> from socket import gethostbyname
>>> gethostbyname('lns.sa')
'67.215.65.132'
>>> gethostbyname('lns.sa')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
>>> gethostbyname('lns.sa')
'67.215.65.132'
>>> gethostbyname('lns.sa')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
>>> gethostbyname('lns.sa')
'67.215.65.132'
>>> gethostbyname('lns.sa')
'67.215.65.132'
>>> gethostbyname('lns.sa')
'67.215.65.132'
>>> gethostbyname('lns.sa')
'67.215.65.132'
>>> gethostbyname('lns.sa')
'67.215.65.132'
>>> gethostbyname('lns.sa')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
>>> 

It gives two diffrent answers, once belonge to OpenDNS and the other is Name or service not known, the right one. After a couple of seconds, it works fine. Could someone explain this behavior and is gethostbyname reliable to be used ?

도움이 되었습니까?

해결책

There's nothing wrong with gethostbyname() at all - the domain lns.sa really doesn't exist.

The address 67.215.65.132 is the one provided by OpenDNS for domains that don't exist. It's name is hit-nxdomain.opendns.com.

Most likely you have one OpenDNS server configured, and one from someone else. OpenDNS are re-writing any "not found" domains, the other provider isn't.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top