[Python-bugs-list] [ python-Bugs-577977 ] socket.gethostbyaddr is too strict

noreply@sourceforge.net noreply@sourceforge.net
Sat, 06 Jul 2002 10:21:47 -0700


Bugs item #577977, was opened at 2002-07-06 00:23
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=577977&group_id=5470

Category: Python Library
Group: Python 2.2.1
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Dave Cinege (dcinege)
Assigned to: Nobody/Anonymous (nobody)
Summary: socket.gethostbyaddr is too strict

Initial Comment:
While using socket.gethostbyaddr() I discovered it will    
not deal with 'bad' ip addresses.     
    
IE: print socket.gethostbyaddr('192.168.0.400')    
python2.2   
socket.gaierror: (-2, 'Name or service not known')   
python2.1   
socket.error: host not found    
   
Now you may be wondering WTF I'm using a bad IP.   
Good question. It is the end result of my quest to make   
machines (that are offline) have their mac addresses  
availab;e for query. DHCP is too difficult, so I tried some  
trickery with DNS. Of the several ways to do this, the  
easist is to create a PTR of the host, and offset it's IP by  
say 300 with a new host name equal to it's mac.   
  
IE  
100 IN  PTR zen-machine.psychosis.com. 
400 IN  PTR 00-A0-CC-60-FE-D1.psychosis.com. 
  
Again WHY all of this? It would be nice to execute  
'wakeonlan <hostname>' instead of keeping track of  
MAC's.  : > 
  
It's all works lovely with BIND 8.2.X. I assume as well  
with bind 9. Bind 8 and bind 9 utils can make the query.  
  
# host 192.168.0.400  
400.0.168.192.in-addr.arpa domain name pointer  
00-A0-CC-60-FE-D1.psychosis.com.  
  
But I found out when writing my util to wrap this all up  
Python's socket pukes.   
  
Now the question is, is socket doing the right thing? It's  
not so clear when you put it in terms of DNS. DNS deals  
with strings, and those string need not nessasarly follow  
the rules of TCP/IP. (BIND's actions above are a perfect  
example) However BIND is no benchmark for proper  
operation.  : P  
 
What I do know is I've had to revert to executing the 
'host' command externally instead of using Pythons 
native interface. 
 
Dave 

----------------------------------------------------------------------

>Comment By: Jeremy Hylton (jhylton)
Date: 2002-07-06 17:21

Message:
Logged In: YES 
user_id=31392

How do you expect to encode 400 as the last byte of an IP
address?  Python can't figure out a way, so it's going to
treat that string as a name and use gethostbyname() to get
an address for it.

If you want, you can re-open the bug report if you can
attach a C program that uses gethostbyaddr() and produces
results different from Python.  When given sane inputs,
Python i just calling the C library gethostbyaddr().


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=577977&group_id=5470