#NEWLINE# @ webapp . route ( '/network' ) #NEWLINE# def view_networks( ) : #NEWLINE# #INDENT# netifs = current_service . get_network_interfaces ( ) . values ( ) #NEWLINE# netifs . sort ( key = ( lambda x : x . get ( 'bytes_sent' ) ) , reverse = True ) #NEWLINE# form_keys = { #NEWLINE# #INDENT# 'pid' : '' , #NEWLINE# 'family' : socket_families [ socket . AF_INET ] , #NEWLINE# 'type' : socket_types [ socket . SOCK_STREAM ] , #NEWLINE# 'state' : 'LISTEN' , #NEWLINE# #UNINDENT# } #NEWLINE# form_values = dict ( ( ( k , request . args . get ( form_keys , default_val ) ) for ( k , default_val ) in form_keys . iteritems ( ) ) ) #NEWLINE# for k in ( 'local_addr' , 'remote_addr' ) : #NEWLINE# #INDENT# val = request . args . get ( k , '' ) #NEWLINE# if ( ':' in val ) : #NEWLINE# #INDENT# ( host , port ) = val . rsplit ( ':' , 1 ) #NEWLINE# form_values [ ( k + '_host' ) ] = host #NEWLINE# form_values [ ( k + '_port' ) ] = int ( port ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if val : #NEWLINE# #INDENT# form_values [ ( k + '_host' ) ] = val #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# conns = current_service . get_connections ( form_values ) #NEWLINE# conns . sort ( key = ( lambda x : x [ 'state' ] ) ) #NEWLINE# states = [ 'ESTABLISHED' , 'SYN_SENT' , 'SYN_RECV' , 'FIN_WAIT1' , 'FIN_WAIT2' , 'TIME_WAIT' , 'CLOSE' , 'CLOSE_WAIT' , 'LAST_ACK' , 'LISTEN' , 'CLOSING' , 'NONE' ] #NEWLINE# return render_template ( 'network.html' , page = 'network' , network_interfaces = netifs , connections = conns , socket_families = socket_families , socket_types = socket_types , states = states , is_xhr = request . is_xhr , num_conns = len ( conns ) , ** form_values )