getservbyport() in Python?

Justin Sheehy dworkin at ccs.neu.edu
Mon Jan 10 13:49:04 EST 2000


jeffg at provenance.com.au writes:

> Does anyone know of any Python implementation of the Linux standard call
> getservbyport()? This function is given a network socket port number and
> returns the service name. eg if passed 80, will return 'http'. This
> information is taken from the /etc/services file.

No, it seems as though getservbyname exists, but its sister calls are
unimplemented.  

And you would probably want to be more specific, saying that passing
80 and 'tcp' would return http.

> If nothing exists (& I've looked around pretty thoroughly), then I plan
> to scan the services file directly, using re to search for the port
> number I want.

You may be better off using `string' for that searching, not `re'.

Of course, the _real_ way to do this is to patch socketmodule.c to
call the underlying getservbyport function.  It should be pretty much
a cut-and-paste job from the getservbyname implementation.

-Justin

 




More information about the Python-list mailing list