retrieve whois information and parse again without connection to server

This commit is contained in:
2020-04-22 08:27:10 +02:00
parent e12127f6dd
commit 0e21c9baf7

View File

@ -34,11 +34,11 @@ public class Whois {
/**
* whoisClient client from commons-net package to execute commands with
*/
WhoisClient whoisClient;
private WhoisClient whoisClient;
/**
* the complete output
*/
String whoisString = null;
private String whoisString = null;
private static final List<String> WHOIS_SERVERS;
@ -79,8 +79,7 @@ public class Whois {
}
/**
* reads and parses the inforomation for the given ip address from the given
* whoisserver
* reads and parses the inforomation for the given ip address from the given whoisserver
*
* @param whoIsServer the whoisClient server to use
* @param ip the ip to query whoisClient data for
@ -102,16 +101,34 @@ public class Whois {
} catch (Exception ex) {
throw new WhoisException("Error while reading whois data from " + whoIsServer + ". Reason: " + ex.getMessage(), ex);
}
return parseWhoisInformation (whoisString);
}
public static WhoisInformation parse(String whoisInformation) throws WhoisException {
return parseWhoisInformation (whoisInformation);
}
private static WhoisInformation parseWhoisInformation (String whoisInformation) throws WhoisException {
// identify RIR and select correct parser
WhoisParser parser;
if (whoisString.toLowerCase(Locale.US).contains("arin.net")) {
if (whoisInformation.toLowerCase(Locale.US).contains("arin.net")) {
parser = new ArinWhoisParser();
} else {
parser = new DefaultWhoisParser();
}
return parser.parseWhoIsString(whoisString);
return parser.parseWhoIsString(whoisInformation);
}
/**
* returns the output received from the whois server
*
* @return the output received from the whois server
*/
public String getWhoisString() {
return whoisString;
}
}