Libraryless. Click here for Pure Java version (253L/3K/10K).
1 | !747 |
2 | |
3 | m {
|
4 | static int threads = 10; |
5 | static int timeout = 500; // SHOULD be enough... |
6 | static String ip = "127.0.0.1"; |
7 | |
8 | static class Program {
|
9 | int port; |
10 | String helloString; |
11 | |
12 | *(int *port, String *helloString) {}
|
13 | } |
14 | |
15 | p {
|
16 | final ExecutorService es = Executors.newFixedThreadPool(threads); |
17 | print("Program-scanning " + ip + " with timeout " + timeout + " ms in " + threads + " threads.");
|
18 | startTiming(); |
19 | new List<Future<Program>> futures; |
20 | for (int port = 1; port <= 65535; port++) {
|
21 | futures.add(checkPort(es, ip, port, timeout)); |
22 | } |
23 | es.shutdown(); |
24 | new List<Program> programs; |
25 | for (final Future<Program> f : futures) {
|
26 | Program p = f.get(); |
27 | if (p != null) |
28 | programs.add(p); |
29 | } |
30 | stopTiming(); |
31 | System.out.println("Found " + programs.size() + " program(s) on " + ip + ": " + structure(programs));
|
32 | } |
33 | |
34 | public static Future<Program> checkPort(final ExecutorService es, final String ip, final int port, final int timeout) {
|
35 | return es.submit(new Callable<Program>() {
|
36 | @Override public Program call() {
|
37 | try {
|
38 | Socket socket = new Socket(); |
39 | socket.setSoTimeout(timeout); |
40 | socket.connect(new InetSocketAddress(ip, port), timeout); |
41 | print("Connected to " + ip + ":" + port);
|
42 | BufferedReader in = new BufferedReader( |
43 | new InputStreamReader(socket.getInputStream(), "UTF-8")); |
44 | S hello = in.readLine(); |
45 | socket.close(); |
46 | return new Program(port, hello); |
47 | } catch (Exception ex) {
|
48 | return null; |
49 | } |
50 | } |
51 | }); |
52 | } |
53 | } |
Began life as a copy of #1000796
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000802 |
| Snippet name: | Program scan! |
| Eternal ID of this version: | #1000802/1 |
| Text MD5: | d3749be90a34534028fa6d8cb6723e2d |
| Transpilation MD5: | aaac5f66b439030461c99c243c6bbd99 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-28 16:34:13 |
| Source code size: | 1706 bytes / 53 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 937 / 1054 |
| Referenced in: | [show references] |