socket.inet_ntop, and pton question
Mahesh Poojary S
smpoojary at gmail.com
Wed Aug 5 05:11:38 EDT 2009
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_ntop%2C-and-pton-question-tp8677935p24823395.html
Sent from the Python - python-list mailing list archive at Nabble.com.
More information about the Python-list
mailing list