!747 !actionListener { !x619 // standard classes (LetterLayout, CenteredLine) !multi-line strings !1000805 // awt { main { static JList list; static JTextField tfCmd; // unused static JLabel status; static JButton btnScan; static S ip; static int fromPort = 10000, toPort = 10999; !include #1000804 // ProgramScan static S menuSnippet = "#1000910"; static S menuScript; !include #1000839 // PopupMenuHelper psvm { if (args.length != 0) ip = args[0]; S title = "Running programs and bots"; if (ip != null) title += " on " + ip; installHelloMessage(title); JFrame frame = new JFrame(title); JPanel panel = new JPanel(new BorderLayout()); list = new JList(); panel.add(BorderLayout.CENTER, new JScrollPane(list)); new PopupMenuHelper() { void fillMenu() { try { if (menuScript == null) menuScript = loadSnippet(menuSnippet); JMenuItem mi; int idx = list.locationToIndex(point); final String item = cast list.getModel().getElementAt(idx); list.setSelectedIndex(idx); L tok = javaTok(menuScript); for (int i = 1; i+4 < tok.size(); i += 2) if (tok.get(i+2).equals("=")) { final S snip = unquote(tok.get(i+4)); S text = unquote(tok.get(i)); mi = new JMenuItem(text); mi.addActionListener(actionListener { runCustom(snip, item); }); menu.add(mi); } } catch (Throwable e) { popup(e); } } }.install(list); tfCmd = new JTextField(); //panel.add(BorderLayout.SOUTH, tfCmd) status = new JLabel(" "); btnScan = new JButton("Scan again"); btnScan.addActionListener(actionListener { scan(); }); JPanel bottom = new JPanel(new BorderLayout()); bottom.add(BorderLayout.CENTER, status); bottom.add(BorderLayout.EAST, btnScan); panel.add(BorderLayout.SOUTH, bottom); /*tfCmd.addActionListener(actionListener { tfCmd.selectAll(); String cmd = tfCmd.getText(); runCmd(cmd); });*/ /*frame.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { tfCmd.requestFocus(); } });*/ frame.add(panel); frame.setBounds(100, 100, 500, 400); frame.setVisible(true); exitOnFrameClose(frame); scan(); } static void scan() { thread { status("Scanning " + (ip != null ? ip + " " : "") + " for programs..."); btnScan.setEnabled(false); try { if (ip != null) ProgramScan.ip = ip; final List programs = ProgramScan.scan(fromPort, toPort); programs.addAll(ProgramScan.quickBotScan()); status("Done. " + programs.size() + " programs or bots found."); awt { new DefaultListModel model; for (ProgramScan.Program p : programs) model.addElement("Port " + p.port + ": " + p.helloString); list.setModel(model); } } catch (Throwable e) { e.printStackTrace(); status("Scan error: " + e); } btnScan.setEnabled(true); } } static void status(final S s) { awt { status.setText(s); } } static void runCustom(S worker, S item) { item = item.replaceAll("^[^0-9]*", ""); int i = item.indexOf(":"); nohupJavax(worker + " " + (ip == null ? "" : ip + " ") + item.substring(0, i) + " by the name of " + quote(item.substring(i+1).trim())); } !include #1001139 // quickBotScan included for technical reasons }