speed-up of network port scanner

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7719 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent b04382bc59
commit bade61696f

@ -46,6 +46,8 @@ import de.anomic.server.serverSwitch;
public class CrawlStartScanner_p { public class CrawlStartScanner_p {
private final static int CONCURRENT_RUNNER = 100;
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final serverObjects prop = new serverObjects(); final serverObjects prop = new serverObjects();
@ -104,7 +106,7 @@ public class CrawlStartScanner_p {
if (p >= 0) host = host.substring(0, p); if (p >= 0) host = host.substring(0, p);
ia.add(Domains.dnsResolve(host)); ia.add(Domains.dnsResolve(host));
} }
final Scanner scanner = new Scanner(ia, 100, sb.isIntranetMode() ? 1000 : 5000); final Scanner scanner = new Scanner(ia, CONCURRENT_RUNNER, sb.isIntranetMode() ? 100 : 3000);
if (post.get("scanftp", "").equals("on")) scanner.addFTP(false); if (post.get("scanftp", "").equals("on")) scanner.addFTP(false);
if (post.get("scanhttp", "").equals("on")) scanner.addHTTP(false); if (post.get("scanhttp", "").equals("on")) scanner.addHTTP(false);
if (post.get("scanhttps", "").equals("on")) scanner.addHTTPS(false); if (post.get("scanhttps", "").equals("on")) scanner.addHTTPS(false);
@ -119,7 +121,7 @@ public class CrawlStartScanner_p {
} }
if (post.containsKey("scan") && "intranet".equals(post.get("source", ""))) { if (post.containsKey("scan") && "intranet".equals(post.get("source", ""))) {
final Scanner scanner = new Scanner(Domains.myIntranetIPs(), 100, sb.isIntranetMode() ? 100 : 3000); final Scanner scanner = new Scanner(Domains.myIntranetIPs(), CONCURRENT_RUNNER, sb.isIntranetMode() ? 100 : 3000);
if ("on".equals(post.get("scanftp", ""))) scanner.addFTP(false); if ("on".equals(post.get("scanftp", ""))) scanner.addFTP(false);
if ("on".equals(post.get("scanhttp", ""))) scanner.addHTTP(false); if ("on".equals(post.get("scanhttp", ""))) scanner.addHTTP(false);
if ("on".equals(post.get("scanhttps", ""))) scanner.addHTTPS(false); if ("on".equals(post.get("scanhttps", ""))) scanner.addHTTPS(false);

@ -197,7 +197,7 @@
#(/versioning)# #(/versioning)#
<p class="Navigation"> <p class="Navigation">
<a href="Wiki.html">Start Page</a> - <a href="Wiki.html">Start Page</a> -
<a href="Wiki.html?page=#[page]#&amp;">Return to #[page]#</a> <a href="Wiki.html?page=#[page]#">Return to #[page]#</a>
</p> </p>
#(/mode)# #(/mode)#

@ -202,7 +202,7 @@ public class Scanner extends Thread {
/*for (Runner r: runner.keySet()) { /*for (Runner r: runner.keySet()) {
if (r.age() > 3000) synchronized(r) { r.interrupt(); } if (r.age() > 3000) synchronized(r) { r.interrupt(); }
}*/ }*/
if (runner.size() >= this.runnerCount) Thread.sleep(1000); if (runner.size() >= this.runnerCount) Thread.sleep(30);
} }
Runner runner = new Runner(uri); Runner runner = new Runner(uri);
this.runner.put(runner, PRESENT); this.runner.put(runner, PRESENT);

@ -112,17 +112,23 @@ public class TimeoutRequest<E> {
public static boolean ping(final String host, final int port, final int timeout) throws ExecutionException { public static boolean ping(final String host, final int port, final int timeout) throws ExecutionException {
return new TimeoutRequest<Boolean>(new Callable<Boolean>() { return new TimeoutRequest<Boolean>(new Callable<Boolean>() {
public Boolean call() { public Boolean call() {
//long time = System.currentTimeMillis();
try { try {
Socket socket = new Socket(); Socket socket = new Socket();
//System.out.println("PING socket create = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();
socket.connect(new InetSocketAddress(host, port), timeout); socket.connect(new InetSocketAddress(host, port), timeout);
//System.out.println("PING socket connect = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();
if (socket.isConnected()) { if (socket.isConnected()) {
socket.close(); socket.close();
return Boolean.TRUE; return Boolean.TRUE;
} }
//System.out.println("PING socket close = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();
return Boolean.FALSE; return Boolean.FALSE;
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
//System.out.println("PING socket UnknownHostException = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();
return Boolean.FALSE; return Boolean.FALSE;
} catch (IOException e) { } catch (IOException e) {
//System.out.println("PING socket IOException = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();
return Boolean.FALSE; return Boolean.FALSE;
} }
} }

Loading…
Cancel
Save