Exemplo n.º 1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mScanToggleButton = (ToggleButton) findViewById(R.id.scanToggleButton);
    mScanProgress = (ProgressBar) findViewById(R.id.scanActivity);

    mScanToggleButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mRunning) {
              setStoppedState();
            } else {
              setStartedState();
            }
          }
        });

    ListView mScanList = (ListView) findViewById(R.id.scanListView);

    for (Port port : System.getCurrentTarget().getOpenPorts()) {
      mPortList.add(port.number + " ( " + port.protocol.toString().toLowerCase() + " )");
    }

    mListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mPortList);
    mScanList.setAdapter(mListAdapter);
    mScanList.setOnItemLongClickListener(
        new OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            int portNumber = System.getCurrentTarget().getOpenPorts().get(position).number;
            String url = "";

            if (portNumber == 80)
              url = "http://" + System.getCurrentTarget().getCommandLineRepresentation() + "/";
            else if (portNumber == 443)
              url = "https://" + System.getCurrentTarget().getCommandLineRepresentation() + "/";
            else if (portNumber == 21)
              url = "ftp://" + System.getCurrentTarget().getCommandLineRepresentation();
            else if (portNumber == 22)
              url = "ssh://" + System.getCurrentTarget().getCommandLineRepresentation();
            else
              url =
                  "telnet://"
                      + System.getCurrentTarget().getCommandLineRepresentation()
                      + ":"
                      + portNumber;

            final String furl = url;

            new ConfirmDialog(
                    "Open",
                    "Open " + url + " ?",
                    PortScanner.this,
                    new ConfirmDialogListener() {
                      @Override
                      public void onConfirm() {
                        try {
                          Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(furl));

                          PortScanner.this.startActivity(browser);
                        } catch (ActivityNotFoundException e) {
                          System.errorLogging(e);

                          new ErrorDialog(
                                  getString(R.string.error),
                                  getString(R.string.no_activities_for_url),
                                  PortScanner.this)
                              .show();
                        }
                      }

                      @Override
                      public void onCancel() {}
                    })
                .show();

            return false;
          }
        });
  }
Exemplo n.º 2
0
 @Override
 public void onBackPressed() {
   setStoppedState();
   super.onBackPressed();
 }