Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

network protocols

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


tarek at ziade

Jun 13, 2012, 4:41 AM

Post #1 of 6 (243 views)
Permalink
network protocols

Hey

I was surprised not to find any way to list all protocol names listed in
/etc/protocols in Python

We have

socket.getprotobyname(NAME)

But there's no way to get the list of names

Any ideas if this is available in the stdlib somehwere ?

Thx
Tarek
--
http://mail.python.org/mailman/listinfo/python-list


jsutter55 at hotmail

Jun 13, 2012, 7:10 AM

Post #2 of 6 (225 views)
Permalink
RE: network protocols [In reply to]

Tarek,

There doesn't appear to be a function in stdlib to cover that particular case.

Doug Hellman has a nice section on finding service info here:

http://www.doughellmann.com/PyMOTW/socket/addressing.html

It wouldn't be "built-in", but it looks like it would be pretty simple to get the info you need.

Best regards,

JS

> Date: Wed, 13 Jun 2012 13:41:25 +0200
> From: tarek [at] ziade
> To: python-list [at] python
> Subject: network protocols
>
> Hey
>
> I was surprised not to find any way to list all protocol names listed in
> /etc/protocols in Python
>
> We have
>
> socket.getprotobyname(NAME)
>
> But there's no way to get the list of names
>
> Any ideas if this is available in the stdlib somehwere ?
>
> Thx
> Tarek
> --
> http://mail.python.org/mailman/listinfo/python-list


tdldev at gmail

Jun 13, 2012, 7:50 AM

Post #3 of 6 (225 views)
Permalink
Re: network protocols [In reply to]

On 6/13/12, John Sutterfield <jsutter55 [at] hotmail> wrote:
>
> Tarek,
>
> There doesn't appear to be a function in stdlib to cover that particular
> case.
>
> Doug Hellman has a nice section on finding service info here:
>
> http://www.doughellmann.com/PyMOTW/socket/addressing.html
>
> It wouldn't be "built-in", but it looks like it would be pretty simple to
> get the info you need.
>
> Best regards,
>
> JS
>
JS
Very nice link! Great information here.

-- Jack

>> Date: Wed, 13 Jun 2012 13:41:25 +0200
>> From: tarek [at] ziade
>> To: python-list [at] python
>> Subject: network protocols
>>
>> Hey
>>
>> I was surprised not to find any way to list all protocol names listed in
>> /etc/protocols in Python
>>
>> We have
>>
>> socket.getprotobyname(NAME)
>>
>> But there's no way to get the list of names
>>
>> Any ideas if this is available in the stdlib somehwere ?
>>
>> Thx
>> Tarek
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


lists at cheimes

Jun 13, 2012, 7:56 AM

Post #4 of 6 (225 views)
Permalink
Re: network protocols [In reply to]

Am 13.06.2012 13:41, schrieb Tarek Ziadé:
> Hey
>
> I was surprised not to find any way to list all protocol names listed in
> /etc/protocols in Python
>
> We have
>
> socket.getprotobyname(NAME)
>
> But there's no way to get the list of names
>
> Any ideas if this is available in the stdlib somehwere ?

No, I can't find any reference to the relevant NSS APIs in the Python
code. You can easily roll your own with ctypes:


from ctypes import *
libc = CDLL("libc.so.6")

class protoent(Structure):
_fields_ = [("p_name", c_char_p),
("p_aliases", POINTER(c_char_p)),
("p_proto", c_int)]

libc.getprotoent.restype = POINTER(protoent)

# open database
libc.setprotoent(0)

while True:
pr = libc.getprotoent()
if not pr:
break
r = pr[0]
print r.p_name, r.p_proto

# close database
libc.endprotoent()

--
http://mail.python.org/mailman/listinfo/python-list


lists at cheimes

Jun 13, 2012, 11:33 AM

Post #5 of 6 (220 views)
Permalink
Re: network protocols [In reply to]

Am 13.06.2012 16:56, schrieb Christian Heimes:
> Am 13.06.2012 13:41, schrieb Tarek Ziadé:
>> Hey
>>
>> I was surprised not to find any way to list all protocol names listed in
>> /etc/protocols in Python
>>
>> We have
>>
>> socket.getprotobyname(NAME)
>>
>> But there's no way to get the list of names
>>
>> Any ideas if this is available in the stdlib somehwere ?
>
> No, I can't find any reference to the relevant NSS APIs in the Python
> code. You can easily roll your own with ctypes:

PS: You can also parse the output of "getent protocols". As for all name
services you shouldn't parse the file as other sources (ldap, dns, nis,
databases) can provide additional information. See man nsswitch.conf

Christian

--
http://mail.python.org/mailman/listinfo/python-list


tarek at ziade

Jun 13, 2012, 11:58 AM

Post #6 of 6 (221 views)
Permalink
Re: network protocols [In reply to]

On 6/13/12 8:33 PM, Christian Heimes wrote:
> Am 13.06.2012 16:56, schrieb Christian Heimes:
>> Am 13.06.2012 13:41, schrieb Tarek Ziadé:
>>> Hey
>>>
>>> I was surprised not to find any way to list all protocol names listed in
>>> /etc/protocols in Python
>>>
>>> We have
>>>
>>> socket.getprotobyname(NAME)
>>>
>>> But there's no way to get the list of names
>>>
>>> Any ideas if this is available in the stdlib somehwere ?
>> No, I can't find any reference to the relevant NSS APIs in the Python
>> code. You can easily roll your own with ctypes:
> PS: You can also parse the output of "getent protocols". As for all name
> services you shouldn't parse the file as other sources (ldap, dns, nis,
> databases) can provide additional information. See man nsswitch.conf
>
> Christian
>
Thanks for the pointers -- I was going to
open('etc/protocols').readlines() :)
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.