Module netstat :: Class NetProcess
[hide private]
[frames] | no frames]

Class NetProcess

source code


Class NetProcess represents one network connection. Most of the properties are read from /proc/net/{tcp,udp,raw} lines. The class uses dictionary-like mapping.

The fields we remember about a process are described in NetProcess.keys. Mapping of someof them to fields in /proc/net file are in NetProcess.keys. In order to save some space, TCP states are stored in NetProcess.states and every process has only an integer pointing into this list.

Instance Methods [hide private]
 
__eq__(self, other)
Comparison operaton.
source code
 
__neq__(self, other)
Negative comparison operaton Returns True if the object holds the same data as the other object.
source code
 
__repr__(self)
Prints out a human readable representation of the structure that can be easily used to recreate the same object
source code
 
__str__(self)
Returns human-readable representation of the object
source code
 
__resolve_ip(self, address)
Tries to resolve a hostname for a given IP.
source code
 
__resolve_portnum(self, portnum)
Tries to resolve a service name for a given portnum.
source code
 
__check_key(self, key)
The strategy is: if we are asked for a key we should not know, raise exception.
source code
 
__getitem__(self, key)
Return item or N/A if not set.
source code
 
__setitem__(self, key, value)
Adjust value of a key.
source code
 
__init__(self, line)
Parses given line and stores in an internal dictionary (see UserDict)
source code
 
__parse_address(self, addr)
Adresses in the /proc/net/{tcp,udp} file are in reverse byte-order.
source code
 
__parse_line(self, line)
Splits fields of a given line and stores them in self-dictionary (see UserDict).
source code

Inherited from UserDict.UserDict: __cmp__, __contains__, __delitem__, __len__, clear, copy, get, has_key, items, iteritems, iterkeys, itervalues, pop, popitem, setdefault, update, values

Class Methods [hide private]

Inherited from UserDict.UserDict: fromkeys

Class Variables [hide private]
  keys = ['addr_local', 'port_local', 'addr_remote', 'port_remot...
  fields = {'addr_local': 1, 'addr_remote': 2, 'inode': 9, 'stat...
  states = ['none', 'Established', 'Syn-Sent', 'Syn-Recv', 'Fin-...
Method Details [hide private]

__eq__(self, other)
(Equality operator)

source code 
Comparison operaton. Returns True if the object holds the same data as the other object.

__repr__(self)
(Representation operator)

source code 
Prints out a human readable representation of the structure that can be easily used to recreate the same object
Overrides: UserDict.UserDict.__repr__

__resolve_ip(self, address)

source code 
Tries to resolve a hostname for a given IP. If not successfull, returns the IP adress back

__resolve_portnum(self, portnum)

source code 
Tries to resolve a service name for a given portnum. If not successfull, returns the port number back

__check_key(self, key)

source code 
The strategy is: if we are asked for a key we should not know, raise exception. If we are asked for a key we should know, but for some reason we don't (such as could not find icon, or could not resolve pid for a root program) we return N/A

__getitem__(self, key)
(Indexing operator)

source code 
Return item or N/A if not set. Raises KeyError if the key is not in NetProcess.keys
Overrides: UserDict.UserDict.__getitem__

__setitem__(self, key, value)
(Index assignment operator)

source code 
Adjust value of a key. Raises KeyError if the key is not in NetProcess.keys.
Overrides: UserDict.UserDict.__setitem__

__init__(self, line)
(Constructor)

source code 
Parses given line and stores in an internal dictionary (see UserDict)
Overrides: UserDict.UserDict.__init__

__parse_address(self, addr)

source code 
Adresses in the /proc/net/{tcp,udp} file are in reverse byte-order. This file converts it to human-readable notation and returns a tuple of: ('address', port)

__parse_line(self, line)

source code 
Splits fields of a given line and stores them in self-dictionary (see UserDict). Raises IndexError if the line does not have correct number of fields or ValueError if a field does not contain the info it should.

Class Variable Details [hide private]

keys

Value:
['addr_local',
 'port_local',
 'addr_remote',
 'port_remote',
 'pid',
 'inode',
 'uid',
 'state',
...

fields

Value:
{'addr_local': 1, 'addr_remote': 2, 'inode': 9, 'state': 3, 'uid': 7}

states

Value:
['none',
 'Established',
 'Syn-Sent',
 'Syn-Recv',
 'Fin-Wait1',
 'Fin-Wait2',
 'Time-Wait',
 'Close',
...