Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Python - socket.inet_ntop, and pton question

 
Thread Tools Search this Thread
Old 01-28-2007, 05:38 PM   #1
Default socket.inet_ntop, and pton question


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
  Reply With Quote
Old 01-28-2007, 06:17 PM   #2
Irmen de Jong
 
Posts: n/a
Default Re: socket.inet_ntop, and pton question
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
  Reply With Quote
Old 01-29-2007, 02:08 AM   #3
Gabriel Genellina
 
Posts: n/a
Default Re: socket.inet_ntop, and pton question
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
  Reply With Quote
Old 01-29-2007, 02:27 AM   #4
Irmen de Jong
 
Posts: n/a
Default Re: socket.inet_ntop, and pton question
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
  Reply With Quote
Old 01-31-2007, 05:34 AM   #5
Andrew
 
Posts: n/a
Default Re: socket.inet_ntop, and pton question
Hi I just thought I would mention that I found what I needed from dnspython

if anyone ever needs

http://www.dnspython.org/


Andrew
  Reply With Quote
Old 08-05-2009, 10:11 AM   #6
Mahesh Poojary S
 
Posts: n/a
Default Re: socket.inet_ntop, and pton question



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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46