improved whois

This commit is contained in:
Joern Muehlencord
2022-03-01 08:53:41 +01:00
parent ec82f06f88
commit 698ddfd199
5 changed files with 100 additions and 35 deletions

View File

@ -19,7 +19,6 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
*
* @author Joern Muehlencord (joern@muehlencord.de) * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class AbstractWhoisParser implements WhoisParser { public abstract class AbstractWhoisParser implements WhoisParser {
@ -29,6 +28,7 @@ public abstract class AbstractWhoisParser implements WhoisParser {
String[] lines = blockString.split("\n"); String[] lines = blockString.split("\n");
for (String line : lines) { for (String line : lines) {
if (!line.startsWith("%")) {
String key; String key;
String value; String value;
if (line.indexOf(" ") == -1) { if (line.indexOf(" ") == -1) {
@ -39,9 +39,9 @@ public abstract class AbstractWhoisParser implements WhoisParser {
value = line.substring(line.indexOf(" ")); value = line.substring(line.indexOf(" "));
value = value.trim(); value = value.trim();
} }
returnMap.put(key, value); returnMap.put(key, value);
} }
}
return returnMap; return returnMap;
} }

View File

@ -49,6 +49,10 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
// if re-allocated just return empty whoisInformation because this RIR is not responsible // if re-allocated just return empty whoisInformation because this RIR is not responsible
if (whoisString.contains("Allocated to LACNIC")) { if (whoisString.contains("Allocated to LACNIC")) {
throw new WhoisException("Allocated to LACNIC"); throw new WhoisException("Allocated to LACNIC");
} else if (whoisString.contains ("NON-RIPE-NCC-MANAGED-ADDRESS-BLOCK")) {
throw new WhoisException("Not managed by RIPE");
} else if (whoisString.contains ("This network range is not allocated to APNIC")) {
throw new WhoisException("Not allocated to APNIC");
} }
whoisInformation.setResponseString(whoisString); whoisInformation.setResponseString(whoisString);

View File

@ -18,6 +18,7 @@ package de.muehlencord.shared.network.whois;
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList; import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -40,16 +41,18 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
// if re-allocated just return empty whoisInformation because this RIR is not responsible // if re-allocated just return empty whoisInformation because this RIR is not responsible
if (whoisString.contains("Allocated to LACNIC")) { if (whoisString.contains("Allocated to LACNIC")) {
throw new WhoisException("Allocated to LACNIC"); throw new WhoisException("Allocated to LACNIC");
} else if (whoisString.contains ("NON-RIPE-NCC-MANAGED-ADDRESS-BLOCK")) {
throw new WhoisException("Not managed by RIPE");
} else if (whoisString.contains ("This network range is not allocated to APNIC")) {
throw new WhoisException("Not allocated to APNIC");
} }
whoisInformation = new WhoisInformation(); whoisInformation = new WhoisInformation();
whoisInformation.setResponseString(whoisString); whoisInformation.setResponseString(whoisString);
// split by blank lines to identify blocks // split by blank lines to identify blocks
String[] blocks; String[] blocks = whoisString.split ("\\R\\R");
if (whoisString.contains("\r\n")) { if (blocks.length == 1) {
blocks = whoisString.split("\r\n\r\n"); blocks = whoisString.lines().collect(Collectors.toList()).toArray(new String[0]);
} else {
blocks = whoisString.split("\n\n");
} }
for (String block : blocks) { for (String block : blocks) {
analyseBlock(block); analyseBlock(block);
@ -81,7 +84,13 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
case "inetnum:": case "inetnum:":
String inetnum = getValue("inetnum:", valueMap); String inetnum = getValue("inetnum:", valueMap);
String country = getValue("country:", valueMap); String country = getValue("country:", valueMap);
if (country == null && block.contains (".br")) {
country = "BR";
}
String netname = getValue("netname:", valueMap); String netname = getValue("netname:", valueMap);
if (netname == null) {
netname = getValue ("owner:", valueMap);
}
String descr = getValue("descr:", valueMap); String descr = getValue("descr:", valueMap);
if ((inetnum == null) || (country == null)) { if ((inetnum == null) || (country == null)) {

View File

@ -87,9 +87,13 @@ public class WhoisTest extends BaseTest {
// whoIsClient.execute("whois.apnic.net", "182.72.111.26"); // whoIsClient.execute("whois.apnic.net", "182.72.111.26");
// whoIsClient.execute("whois.ripe.net", "213.55.95.62"); // Transferred to Afrinic // whoIsClient.execute("whois.ripe.net", "213.55.95.62"); // Transferred to Afrinic
// whoIsClient.execute("whois.afrinic.net", "213.55.95.62"); // whoIsClient.execute("whois.afrinic.net", "213.55.95.62");
// whoIsClient.execute("whois.arin.net", "32.64.68.229"); // whoIsClient.execute("whois.arin.net", "32.64.68.229");
// WhoisInformation info = whoIsClient.execute("whois.lacnic.net", "179.43.168.126");
WhoisInformation info = whoIsClient.execute("179.43.168.126"); // WhoisInformation info = whoIsClient.execute("whois.lacnic.net", "179.43.168.126");
// WhoisInformation info = whoIsClient.execute("143.198.77.103");
// WhoisInformation info = whoIsClient.execute("179.43.168.126");
WhoisInformation info = whoIsClient.execute("187.50.136.210");
System.out.println (info); System.out.println (info);
} }

View File

@ -0,0 +1,48 @@
% Copyright (c) Nic.br
% The use of the data below is only permitted as described in
% full by the terms of use at https://registro.br/termo/en.html ,
% being prohibited its distribution, commercialization or
% reproduction, in particular, to use it for advertising or
% any similar purpose.
% 2022-03-01T03:33:15-03:00 - IP: 88.198.54.68
inetnum: 187.50.0.0/15
aut-num: AS10429
abuse-c: CSTBR
owner: TELEF<45>NICA BRASIL S.A
ownerid: 02.558.157/0001-62
responsible: Diretoria de Planejamento e Tecnologia
owner-c: ARITE
tech-c: GRP95
inetrev: 187.50.136.0/24
nserver: te-br-spo-tic-dns1.tdatabrasil.net.br
nsstat: 20220227 AA
nslastaa: 20220227
nserver: te-br-spo-ib-dns2.tdatabrasil.net.br
nsstat: 20220227 AA
nslastaa: 20220227
created: 20090313
changed: 20190410
nic-hdl-br: ARITE
person: Administra<72><61>o Rede IP Telesp
created: 20080407
changed: 20220104
nic-hdl-br: CSTBR
person: CSIRT TELEFONICA BR
created: 20180713
changed: 20180713
nic-hdl-br: GRP95
person: Grupo Provisionamento
created: 20031027
changed: 20060809
% Security and mail abuse issues should also be addressed to
% cert.br, http://www.cert.br/ , respectivelly to cert@cert.br
% and mail-abuse@cert.br
%
% whois.registro.br accepts only direct match queries. Types
% of queries are: domain (.br), registrant (tax ID), ticket,
% provider, CIDR block, IP and ASN.^M