[Tutor] question about socket status

arsyed arsyed at gmail.com
Wed Jul 23 03:31:47 CEST 2008


On Mon, Jul 21, 2008 at 1:25 PM, Rupp, Romaine <Romaine.Rupp at arrisi.com> wrote:
> Hello,
>
> I am new to programming with python and sockets.
>
> I would like to determine the status of a socket as it  is returned when you
> do 'netstat –a | grep <port#>'.  I would like  to know if the socket state
> is ESTABLISHED, LISTEN , CLOSE_WAIT, etc.
>
> Is there a way to get this information through a socket call?
>
> I've tried using socket.getperrname() function, but that only tells if there
> is a connection.
>
> Is there a way to get more information on the state of the socket
> connection?
>


If you're on linux, you could try poking around /proc/net. See, for example:

http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html

But I think invoking netstat and parsing the output from python might
work well enough.


More information about the Tutor mailing list