!7 static S ip = "tinybrain.de" /*"127.0.0.1"*/; static int count = 1; static boolean result; p { // Java has trouble executing pings, so we use the native command. S cmd = "ping " + (isWindows() ? "-n" : "-c") + " " + count + " " + ip; S output = backtick(cmd); print(output); new Matches m; if (isWindows()) { if (jfind3("reply from *.*.*.*: bytes=* time=* ms ttl=*", output.toLowerCase(), m)) { S ip = m.unq(0) + "." + m.unq(1) + "." + m.unq(2) + "." + m.unq(3); S ttl = m.unq(6), time = m.unq(5); print("Reachable. IP " + ip + " TTL " + ttl + " TIME " + time); } else print("Not reachable."); } else { if (jfind3("(*.*.*.*): *=* ttl=* time=*", output.toLowerCase(), m)) { S ip = m.unq(0) + "." + m.unq(1) + "." + m.unq(2) + "." + m.unq(3); S ttl = m.unq(6), time = m.unq(7); print("Reachable. IP " + ip + " TTL " + ttl + " TIME " + time); } else print("Not reachable."); } } static boolean jfind3(S pat, S s, Matches matches) { if (s == null) return false; ret jfind3(pat, javaTok(s), matches); } static boolean jfind3(S pat, L toks, Matches matches) { L tokpat = javaTok(pat); S[] m = jfind2(tokpat, toks); //print(structure(tokpat) + " on " + structure(toks) + " => " + structure(m)); if (m == null) ret false; else { if (matches != null) matches.m = m; ret true; } } static S[] jfind2(L pat, L tok) { for (int idx = 0; idx < tok.size(); idx += 2) { S[] result = jfind2(pat, tok, idx); if (result != null) return result; } return null; } static S[] jfind2(L pat, L tok, int idx) { if (idx+pat.size() > tok.size()) return null; new L result; for (int i = 1; i < pat.size(); i += 2) { S p = pat.get(i), t = tok.get(idx+i); if (eq(p, "*")) result.add(t); else if (!eq(p, t)) return null; } return toStringArray(result); }