socket.inet_ntop, and pton question

A

Andrew

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
 
I

Irmen de Jong

Andrew said:
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.

This is on windows xp.

--Irmen
 
G

Gabriel Genellina

At said:
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.

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
 
I

Irmen de Jong

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
 
M

Mahesh Poojary S

Martin-298 said:
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top