remotelogin/oper_sys/unix/__init__.py
def tcp_get_connections_from_list(self, netstat_cmd, netstat_listen_cmd, sep, all_interfaces=r'\*', conn=None):
        """ Convert return list of tcp connection pairs from the netstat command. The list would look like:

        10.10.13.35:22 10.10.13.24:17520 on linux (sep=:)
        127.0.0.1.38912 127.0.0.1.5432 on solaris (sep=.)
        """
        connections = []

        # TODO: maybe put all commands to be sshed into one line separated by semi-colon, or implement a multicommand 'send_command' function tha returns a list of results for every command
        # split netstat listen addresses to get the ports and addresses it is listening on:
        o, e = conn.check_output(netstat_listen_cmd)    # o is output string, e is error
        listening_on = collections.defaultdict(list)
        if not e and o:
            for line in o:
                ip, port = line.strip().rsplit(sep, 1)
                if ip == all_interfaces:
                    ip = 'ALL'
                listening_on[ip].append(port)

        # split netstat response pair
        o, e = conn.check_output(netstat_cmd)
        if not e and o:
            for line in o:
                ips = line.strip().split()
                ip_1, port_1 = ips[0].rsplit(sep, 1)     # local ip and port
                ip_2, port_2 = ips[1].rsplit(sep, 1)
                if port_1 in listening_on['ALL'] or (ip_1 in listening_on and port_1 in listening_on[ip_1]):     # this is a connection to a local service
                    tcp = fdutils.structures.TcpConnection(ip_1, port_1, ip_2, port_2)
                else:
                    tcp = fdutils.structures.TcpConnection(ip_2, port_2, ip_1, port_1)
                connections.append(tcp)

        return connections
 Convert return list of tcp connection pairs from the netstat command. The list would look like:

        10.10.13.35:22 10.10.13.24:17520 on linux (sep=:)
        127.0.0.1.38912 127.0.0.1.5432 on solaris (sep=.)
        
Convert return list of tcp connection pairs from the netstat command.
Convert return list of tcp connection pairs from the netstat command .
def tcp_get_connections_from_list(self, netstat_cmd, netstat_listen_cmd, sep, all_interfaces=r'\*', conn=None):
        connections = []
        o, e = conn.check_output(netstat_listen_cmd)    
        listening_on = collections.defaultdict(list)
        if not e and o:
            for line in o:
                ip, port = line.strip().rsplit(sep, 1)
                if ip == all_interfaces:
                    ip = 'ALL'
                listening_on[ip].append(port)
        o, e = conn.check_output(netstat_cmd)
        if not e and o:
            for line in o:
                ips = line.strip().split()
                ip_1, port_1 = ips[0].rsplit(sep, 1)     
                ip_2, port_2 = ips[1].rsplit(sep, 1)
                if port_1 in listening_on['ALL'] or (ip_1 in listening_on and port_1 in listening_on[ip_1]):     
                    tcp = fdutils.structures.TcpConnection(ip_1, port_1, ip_2, port_2)
                else:
                    tcp = fdutils.structures.TcpConnection(ip_2, port_2, ip_1, port_1)
                connections.append(tcp)
        return connections
def tcp_get_connections_from_list ( self , netstat_cmd , netstat_listen_cmd , sep , all_interfaces = r'\*' , conn = None ) : connections = [ ] o , e = conn . check_output ( netstat_listen_cmd ) listening_on = collections . defaultdict ( list ) if not e and o : for line in o : ip , port = line . strip ( ) . rsplit ( sep , 1 ) if ip == all_interfaces : ip = 'ALL' listening_on [ ip ] . append ( port ) o , e = conn . check_output ( netstat_cmd ) if not e and o : for line in o : ips = line . strip ( ) . split ( ) ip_1 , port_1 = ips [ 0 ] . rsplit ( sep , 1 ) ip_2 , port_2 = ips [ 1 ] . rsplit ( sep , 1 ) if port_1 in listening_on [ 'ALL' ] or ( ip_1 in listening_on and port_1 in listening_on [ ip_1 ] ) : tcp = fdutils . structures . TcpConnection ( ip_1 , port_1 , ip_2 , port_2 ) else : tcp = fdutils . structures . TcpConnection ( ip_2 , port_2 , ip_1 , port_1 ) connections . append ( tcp ) return connections
Convert return list of tcp connection pairs from the netstat command.
Convert return list of tcp connection pairs from the netstat command .
""" Convert return list of tcp connection pairs from the netstat command. The list would look like:

        10.10.13.35:22 10.10.13.24:17520 on linux (sep=:)
        127.0.0.1.38912 127.0.0.1.5432 on solaris (sep=.)
        """ # TODO: maybe put all commands to be sshed into one line separated by semi-colon, or implement a multicommand 'send_command' function tha returns a list of results for every command # split netstat listen addresses to get the ports and addresses it is listening on: # o is output string, e is error # split netstat response pair # local ip and port # this is a connection to a local service
self
netstat_cmd
netstat_listen_cmd
sep
all_interfaces
conn