From 1d280156a2bbbb18903ffa7063381ca6c97ea82b Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Wed, 23 Nov 2016 18:08:15 +0000 Subject: [PATCH] Console: Lookup RI by IP with netmask --- .../src/net/i2p/router/web/NetDbRenderer.java | 32 ++++++++++++++++--- .../src/net/i2p/router/web/SybilRenderer.java | 12 ++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java index dc697b5c69..97acfe9c7b 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java @@ -95,6 +95,21 @@ class NetDbRenderer { } else { boolean notFound = true; Set<RouterInfo> routers = _context.netDb().getRouters(); + int ipMode = 0; + if (ip != null) { + if (ip.endsWith("/24")) { + ipMode = 1; + } else if (ip.endsWith("/16")) { + ipMode = 2; + } else if (ip.endsWith("/8")) { + ipMode = 3; + } + for (int i = 0; i < ipMode; i++) { + int last = ip.lastIndexOf('.'); + if (last > 0) + ip = ip.substring(0, last + 1); + } + } for (RouterInfo ri : routers) { Hash key = ri.getIdentity().getHash(); if ((routerPrefix != null && key.toBase64().startsWith(routerPrefix)) || @@ -106,10 +121,19 @@ class NetDbRenderer { notFound = false; } else if (ip != null) { for (RouterAddress ra : ri.getAddresses()) { - if (ip.equals(ra.getHost())) { - renderRouterInfo(buf, ri, false, true); - notFound = false; - break; + if (ipMode == 0) { + if (ip.equals(ra.getHost())) { + renderRouterInfo(buf, ri, false, true); + notFound = false; + break; + } + } else { + String host = ra.getHost(); + if (host != null && host.startsWith(ip)) { + renderRouterInfo(buf, ri, false, true); + notFound = false; + break; + } } } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java index 6dff26ede0..73d59432f7 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java @@ -501,8 +501,10 @@ class SybilRenderer { int i0 = i >> 16; int i1 = (i >> 8) & 0xff; int i2 = i & 0xff; - buf.append("<p><b>").append(count).append(" floodfills in ").append(i0).append('.') - .append(i1).append('.').append(i2).append(".0/24:</b></p>"); + String sip = i0 + "." + i1 + '.' + i2 + ".0/24"; + buf.append("<p><b>").append(count).append(" floodfills with IP <a href=\"/netdb?ip=") + .append(sip).append("\">").append(sip) + .append("</a>:</b></p>"); for (RouterInfo info : ris) { byte[] ip = getIP(info); if (ip == null) @@ -549,8 +551,10 @@ class SybilRenderer { int i = ii.intValue(); int i0 = i >> 8; int i1 = i & 0xff; - buf.append("<p><b>").append(count).append(" floodfills in ").append(i0).append('.') - .append(i1).append(".0.0/16</b></p>"); + String sip = i0 + "." + i1 + ".0/16"; + buf.append("<p><b>").append(count).append(" floodfills with IP <a href=\"/netdb?ip=") + .append(sip).append("\">").append(sip) + .append("</a></b></p>"); for (RouterInfo info : ris) { byte[] ip = getIP(info); if (ip == null) -- GitLab