def _get_router_sockets(self) -> List:
     """
     :return: The Sockets of the Router.
     """
     socket_lst = list()
     raw_socket_lst = self.network_ctrl.send_command("netstat -taupn")[2:]
     for raw_socket in raw_socket_lst:
         # raw_socket looks like:
         # tcp        0     32 192.168.1.1:22          192.168.1.239:51891     ESTABLISHED 1067/dropbear
         raw_socket = raw_socket.split()
         socket = InternetSocket()
         socket.protocol = raw_socket[0]
         raw_local_address = raw_socket[3].split(":")
         socket.local_address = raw_local_address[0] if len(raw_local_address) == 2 else "::"
         socket.local_port = raw_local_address[-1]
         raw_foreign_address = raw_socket[4].split(":")
         socket.foreign_address = raw_foreign_address[0] if len(raw_foreign_address) == 2 else "::"
         socket.foreign_port = raw_foreign_address[-1]
         raw_process = "-1/error"
         if raw_socket[0] == "tcp":
             socket.state = raw_socket[5]
             raw_process = raw_socket[6].split("/")
         elif raw_socket[0] == "udp":
             raw_process = raw_socket[5].split("/")
         socket.pid = int(raw_process[0])
         socket.program_name = raw_process[1]
         socket_lst.append(socket)
     return socket_lst
示例#2
0
 def _get_router_sockets(self) -> List:
     """
     :return: The Sockets of the Router.
     """
     socket_lst = list()
     raw_socket_lst = self.network_ctrl.send_command("netstat -taupn")[2:]
     for raw_socket in raw_socket_lst:
         # raw_socket looks like:
         # tcp        0     32 192.168.1.1:22          192.168.1.239:51891     ESTABLISHED 1067/dropbear
         raw_socket = raw_socket.split()
         socket = InternetSocket()
         socket.protocol = raw_socket[0]
         raw_local_address = raw_socket[3].split(":")
         socket.local_address = raw_local_address[0] if len(
             raw_local_address) == 2 else "::"
         socket.local_port = raw_local_address[-1]
         raw_foreign_address = raw_socket[4].split(":")
         socket.foreign_address = raw_foreign_address[0] if len(
             raw_foreign_address) == 2 else "::"
         socket.foreign_port = raw_foreign_address[-1]
         raw_process = "-1/error"
         if raw_socket[0] == "tcp":
             socket.state = raw_socket[5]
             raw_process = raw_socket[6].split("/")
         elif raw_socket[0] == "udp":
             raw_process = raw_socket[5].split("/")
         socket.pid = int(raw_process[0])
         socket.program_name = raw_process[1]
         socket_lst.append(socket)
     return socket_lst
示例#3
0
    def test_create_InternetSocket(self):
        socket = InternetSocket()
        socket.protocol = Protocol.tcp
        socket.local_address = "192.168.2.11"
        socket.local_port = "22"
        socket.foreign_address = "0.0.0.0"
        socket.foreign_port = "*"
        socket.state = State.listen
        socket.pid = 11
        socket.program_name = "/path/programm"

        assert isinstance(socket, InternetSocket)

        self.assertEqual(Protocol.tcp, socket.protocol)
        self.assertEqual(ipaddress.ip_address("192.168.2.11"), socket.local_address)
        self.assertEqual("22", socket.local_port)
        self.assertEqual(ipaddress.ip_address("0.0.0.0"), socket.foreign_address)
        self.assertEqual("*", socket.foreign_port)
        self.assertEqual(State.listen, socket.state)
        self.assertEqual(11, socket.pid)
        self.assertEqual("/path/programm", socket.program_name)