Example #1
0
  def test_get_pid_by_port_sockstat(self):
    """
    Tests the get_pid_by_port function with a sockstat response.
    """

    mocking.mock(system.call, mock_call(system.GET_PID_BY_PORT_SOCKSTAT % 9051, GET_PID_BY_PORT_SOCKSTAT_RESULTS))
    self.assertEquals(4397, system.get_pid_by_port(9051))
    self.assertEquals(4397, system.get_pid_by_port("9051"))
    self.assertEquals(None, system.get_pid_by_port(123))
Example #2
0
  def test_get_pid_by_port_sockstat(self, call_mock):
    """
    Tests the get_pid_by_port function with a sockstat response.
    """

    call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_SOCKSTAT % 9051, GET_PID_BY_PORT_SOCKSTAT_RESULTS)
    self.assertEquals(4397, system.get_pid_by_port(9051))
    self.assertEquals(4397, system.get_pid_by_port("9051"))
    self.assertEquals(None, system.get_pid_by_port(123))
Example #3
0
  def test_get_pid_by_port_lsof(self):
    """
    Tests the get_pid_by_port function with a lsof response.
    """

    mocking.mock(system.call, mock_call(system.GET_PID_BY_PORT_LSOF, GET_PID_BY_PORT_LSOF_RESULTS))
    self.assertEquals(1745, system.get_pid_by_port(9051))
    self.assertEquals(1745, system.get_pid_by_port("9051"))
    self.assertEquals(329, system.get_pid_by_port(80))
    self.assertEquals(None, system.get_pid_by_port(123))
Example #4
0
  def test_get_pid_by_port_netstat(self):
    """
    Tests the get_pid_by_port function with a netstat response.
    """

    mocking.mock(system.call, mock_call(system.GET_PID_BY_PORT_NETSTAT, GET_PID_BY_PORT_NETSTAT_RESULTS))
    self.assertEquals(1641, system.get_pid_by_port(9051))
    self.assertEquals(1641, system.get_pid_by_port("9051"))
    self.assertEquals(None, system.get_pid_by_port(631))
    self.assertEquals(None, system.get_pid_by_port(123))
Example #5
0
  def test_get_pid_by_port_lsof(self, call_mock):
    """
    Tests the get_pid_by_port function with a lsof response.
    """

    call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_LSOF, GET_PID_BY_PORT_LSOF_RESULTS)
    self.assertEquals(1745, system.get_pid_by_port(9051))
    self.assertEquals(1745, system.get_pid_by_port("9051"))
    self.assertEquals(329, system.get_pid_by_port(80))
    self.assertEquals(None, system.get_pid_by_port(123))
Example #6
0
  def test_get_pid_by_port_netstat(self, call_mock):
    """
    Tests the get_pid_by_port function with a netstat response.
    """

    call_mock.side_effect = mock_call(system.GET_PID_BY_PORT_NETSTAT, GET_PID_BY_PORT_NETSTAT_RESULTS)
    self.assertEquals(1641, system.get_pid_by_port(9051))
    self.assertEquals(1641, system.get_pid_by_port("9051"))
    self.assertEquals(None, system.get_pid_by_port(631))
    self.assertEquals(None, system.get_pid_by_port(123))
Example #7
0
    def test_get_pid_by_port_sockstat(self):
        """
    Tests the get_pid_by_port function with a sockstat response.
    """

        mocking.mock(
            system.call,
            mock_call(system.GET_PID_BY_PORT_SOCKSTAT % 9051,
                      GET_PID_BY_PORT_SOCKSTAT_RESULTS))
        self.assertEquals(4397, system.get_pid_by_port(9051))
        self.assertEquals(4397, system.get_pid_by_port("9051"))
        self.assertEquals(None, system.get_pid_by_port(123))
Example #8
0
    def test_get_pid_by_port_lsof(self):
        """
    Tests the get_pid_by_port function with a lsof response.
    """

        mocking.mock(
            system.call,
            mock_call(system.GET_PID_BY_PORT_LSOF,
                      GET_PID_BY_PORT_LSOF_RESULTS))
        self.assertEquals(1745, system.get_pid_by_port(9051))
        self.assertEquals(1745, system.get_pid_by_port("9051"))
        self.assertEquals(329, system.get_pid_by_port(80))
        self.assertEquals(None, system.get_pid_by_port(123))
Example #9
0
    def test_get_pid_by_port_netstat(self):
        """
    Tests the get_pid_by_port function with a netstat response.
    """

        mocking.mock(
            system.call,
            mock_call(system.GET_PID_BY_PORT_NETSTAT,
                      GET_PID_BY_PORT_NETSTAT_RESULTS))
        self.assertEquals(1641, system.get_pid_by_port(9051))
        self.assertEquals(1641, system.get_pid_by_port("9051"))
        self.assertEquals(None, system.get_pid_by_port(631))
        self.assertEquals(None, system.get_pid_by_port(123))
Example #10
0
def stop(tortpdir):
   """
   Stop TorTP and restore original network configuration
   """
   try:
      copy2("%s/resolv.conf" % tortpdir, "/etc")
      os.remove("%s/resolv.conf" % tortpdir)
   except IOError:
      notify("TorTP", "[!] TorTP seems already disabled")
      sys.exit(1)
   iptables_down(tortpdir)
   os.kill(system.get_pid_by_port(6969), 2)
   notify("TorTP", "[+] Tor Transparent Proxy disabled")