![]() |
|
|
|||||||
![]() |
Python - socket.inet_ntop, and pton question |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Hi
Are these functions (inet_ntop(), inet_pton()) from the socket library supported on Windows. If not is there an equivalent for them using Windows Ive seen mention of people creating their own in order to use them Appreciate the help ty Andrew |
|
|
|
|
#2 |
|
Posts: n/a
|
Andrew wrote:
> Hi > > Are these functions (inet_ntop(), inet_pton()) from the socket library > supported on Windows. > > If not is there an equivalent for them using Windows > > Ive seen mention of people creating their own in order to use them > > Appreciate the help > > ty Why didn't you just try: [E:\Projects]python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> socket.inet_aton("127.0.0.1") '\x7f\x00\x00\x01' >>> socket.inet_ntoa(_) '127.0.0.1' >>> This is on windows xp. --Irmen Irmen de Jong |
|
|
|
#3 |
|
Posts: n/a
|
At Sunday 28/1/2007 15:17, Irmen de Jong wrote:
> > Are these functions (inet_ntop(), inet_pton()) from the socket library > > supported on Windows. > >Why didn't you just try: > >[E:\Projects]python >Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >(Intel)] on win32 >Type "help", "copyright", "credits" or "license" for more information. > >>> import socket > >>> socket.inet_aton("127.0.0.1") >'\x7f\x00\x00\x01' > >>> socket.inet_ntoa(_) >'127.0.0.1' > >>> But these are not the requested functions, inet_ntop() and inet_pton(): py> socket.inet_ntop Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: 'module' object has no attribute 'inet_ntop' -- Gabriel Genellina Softlab SRL __________________________________________________ Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas Gabriel Genellina |
|
|
|
#4 |
|
Posts: n/a
|
Gabriel Genellina wrote:
> But these are not the requested functions, inet_ntop() and inet_pton(): > > py> socket.inet_ntop > Traceback (most recent call last): > File "<stdin>", line 1, in ? > AttributeError: 'module' object has no attribute 'inet_ntop' > > Oops, my bad. Should have had more coffee before replying I guess. --Irmen Irmen de Jong |
|
|
|
#5 |
|
Posts: n/a
|
Hi I just thought I would mention that I found what I needed from dnspython
if anyone ever needs http://www.dnspython.org/ Andrew |
|
|
|
#6 |
|
Posts: n/a
|
Martin-298 wrote: > > Hi > > Are these functions (inet_ntop(), inet_pton()) from the socket library > supported on Windows. > > If not is there an equivalent for them using Windows > > Ive seen mention of people creating their own in order to use them > > Appreciate the help > > ty > -- > http://mail.python.org/mailman/listinfo/python-list > > You can use the below code: def inet_ntop(address_family, packed_ip): if address_family != AF_INET: raise socket.error, (97, 'Address family not supported by protocol') lIP = [] for ch in packed_ip: lIP.append(str(ord(ch))) strIP = string.join(lIP,'.') return strIP def inet_pton(address_family, ip_string): if address_family != AF_INET: raise socket.error, (97, 'Address family not supported by protocol') lIP = ip_string.split('.') strHexIP = "" for i in lIP: if i == '': continue strHex = "%x" % int(i) strHex = strHex.zfill(2) strHexIP += "\\x"+strHex return strHexIP -- View this message in context: http://www.nabble.com/socket.inet_nt...p24823395.html Sent from the Python - python-list mailing list archive at Nabble.com. Mahesh Poojary S |
|
![]() |
| Thread Tools | Search this Thread |
|
|