improved Whois parsing
This commit is contained in:
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
public abstract class AbstractWhoisParser implements WhoisParser {
|
||||
|
||||
protected Map<String, String> getValueMap(String blockString) {
|
||||
Map<String, String> returnMap = new HashMap<>();
|
||||
|
||||
String[] lines = blockString.split("\n");
|
||||
for (String line : lines) {
|
||||
String key;
|
||||
String value;
|
||||
if (line.indexOf(" ") == -1) {
|
||||
key = line;
|
||||
value = "";
|
||||
} else {
|
||||
key = line.substring(0, line.indexOf(" "));
|
||||
value = line.substring(line.indexOf(" "));
|
||||
value = value.trim();
|
||||
}
|
||||
|
||||
returnMap.put(key, value);
|
||||
}
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
protected String getValue(String key, Map<String, String> valueMap) {
|
||||
if (valueMap.containsKey(key)) {
|
||||
return valueMap.get(key);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
*/
|
||||
public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser {
|
||||
|
||||
/** logger object */
|
||||
private final static Logger logger = Logger.getLogger(DefaultWhoisParser.class);
|
||||
/** information to be returned */
|
||||
private WhoisInformation whoisInformation;
|
||||
|
||||
@Override
|
||||
public WhoisInformation parseWhoIsString(String whoisString) throws WhoisException {
|
||||
whoisInformation = new WhoisInformation();
|
||||
if (whoisString.contains("# start")) { // multiple values
|
||||
|
||||
String multipleWhoisString = whoisString;
|
||||
|
||||
while (multipleWhoisString.contains("# start")) {
|
||||
String whoisPartString;
|
||||
try {
|
||||
whoisPartString = StringUtil.getValueBetweenKeywords(multipleWhoisString, "# start", "# end");
|
||||
} catch (ParseException ex) {
|
||||
throw new WhoisException("Error while reading whois part elements. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
analyse(whoisPartString);
|
||||
multipleWhoisString = multipleWhoisString.substring(multipleWhoisString.indexOf("# end")+4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
analyse(whoisString);
|
||||
}
|
||||
|
||||
whoisInformation.validate();
|
||||
|
||||
return whoisInformation;
|
||||
}
|
||||
|
||||
private void analyse(String whoisString) throws WhoisException {
|
||||
String[] blocks;
|
||||
if (whoisString.contains("\r\n")) {
|
||||
blocks = whoisString.split("\r\n\r\n");
|
||||
} else {
|
||||
blocks = whoisString.split("\n\n");
|
||||
}
|
||||
for (String block : blocks) {
|
||||
analyseBlock(block);
|
||||
}
|
||||
}
|
||||
|
||||
private void analyseBlock(String block) throws WhoisException {
|
||||
logger.debug("Start analysing block");
|
||||
logger.debug("\n---\n" + block + "\n---\n");
|
||||
|
||||
if ((block == null) || (block.equals("")) || (!block.contains(" "))) {
|
||||
logger.debug("Skippig empty block");
|
||||
return;
|
||||
}
|
||||
|
||||
String startString = block.substring(0, block.indexOf(" "));
|
||||
if (startString.equals("%")) {
|
||||
startString = block.substring(0, block.indexOf(" ", 2));
|
||||
}
|
||||
|
||||
Map<String, String> valueMap = getValueMap(block);
|
||||
|
||||
|
||||
switch (startString) {
|
||||
|
||||
case "NetRange:":
|
||||
if (valueMap.containsKey("NetRange:")) {
|
||||
String netRange = valueMap.get("NetRange:");
|
||||
// convert inetnum to CDIR
|
||||
String[] ipAddresses = netRange.split(" "); // TODO - what happens if not 3 parts are found
|
||||
// FIXME add CDIR notation support
|
||||
String startIpAddress = ipAddresses[0];
|
||||
String endIPAddress = ipAddresses[2];
|
||||
whoisInformation.getNetwork().addAll(CidrTool.rangeToCidrList(startIpAddress, endIPAddress));
|
||||
logger.info("Network:" + whoisInformation.getNetwork().toString());
|
||||
} else {
|
||||
throw new WhoisException("Cannot identify netrange value");
|
||||
}
|
||||
break;
|
||||
|
||||
case "OrgName:":
|
||||
String orgName = getValue("OrgName:", valueMap);
|
||||
String orgId = getValue("OrgId:", valueMap);
|
||||
String country = getValue("Country:", valueMap);
|
||||
|
||||
if ((orgName == null) || (country == null)) {
|
||||
throw new WhoisException("Cannot identify OrgName and/or country value");
|
||||
}
|
||||
if (orgId == null) {
|
||||
orgId = orgName;
|
||||
}
|
||||
whoisInformation.setNetworkInformation(new NetworkInformation(orgName, orgId, country));
|
||||
logger.info("Networkinformation:" + whoisInformation.getNetworkInformation().toString());
|
||||
break;
|
||||
|
||||
|
||||
case "OrgAbuseHandle:":
|
||||
// TODO add abuse handler
|
||||
logger.info("Skipping OrgAbuseHandle block");
|
||||
break;
|
||||
case "OrgTechHandle:":
|
||||
// admin person of network server belongs to
|
||||
logger.info("Skipping OrgTechHandle block");
|
||||
break;
|
||||
|
||||
case "#":
|
||||
logger.info("Skipping comment block");
|
||||
break;
|
||||
default:
|
||||
logger.info("Unknown block found");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisParser {
|
||||
|
||||
/** logger object */
|
||||
private final static Logger logger = Logger.getLogger(DefaultWhoisParser.class);
|
||||
/** information to be returned */
|
||||
private WhoisInformation whoisInformation;
|
||||
|
||||
@Override
|
||||
public WhoisInformation parseWhoIsString(String whoisString) throws WhoisException {
|
||||
whoisInformation = new WhoisInformation();
|
||||
// split by blank lines to identify blocks
|
||||
String[] blocks;
|
||||
if (whoisString.contains("\r\n")) {
|
||||
blocks = whoisString.split("\r\n\r\n");
|
||||
} else {
|
||||
blocks = whoisString.split("\n\n");
|
||||
}
|
||||
for (String block : blocks) {
|
||||
analyseBlock(block);
|
||||
}
|
||||
|
||||
whoisInformation.validate();
|
||||
|
||||
return whoisInformation;
|
||||
}
|
||||
|
||||
private void analyseBlock(String block) throws WhoisException {
|
||||
logger.debug("Start analysing block");
|
||||
logger.debug("\n---\n" + block + "\n---\n");
|
||||
|
||||
if ((block == null) || (block.equals("")) || (!block.contains(" "))) {
|
||||
logger.debug("Skippig empty block");
|
||||
return;
|
||||
}
|
||||
|
||||
String startString = block.substring(0, block.indexOf(" "));
|
||||
if (startString.equals("%")) {
|
||||
startString = block.substring(0, block.indexOf(" ", 2));
|
||||
}
|
||||
|
||||
Map<String, String> valueMap = getValueMap(block);
|
||||
|
||||
switch (startString) {
|
||||
|
||||
case "inetnum:":
|
||||
|
||||
String inetnum = getValue("inetnum:", valueMap);
|
||||
String country = getValue("country:", valueMap);
|
||||
String netname = getValue("descr:", valueMap);
|
||||
String descr = getValue("netname:", valueMap);
|
||||
|
||||
if ((inetnum == null) || (country == null)) {
|
||||
throw new WhoisException("Cannot identify inetnum and/or country value");
|
||||
}
|
||||
|
||||
if (inetnum.contains(" ")) {
|
||||
// convert inetnum to CDIR
|
||||
String[] ipAddresses = inetnum.split(" "); // TODO - what happens if not 3 parts are found
|
||||
// FIXME add CDIR notation support
|
||||
String startIpAddress = ipAddresses[0];
|
||||
String endIPAddress = ipAddresses[2];
|
||||
whoisInformation.getNetwork().addAll(CidrTool.rangeToCidrList(startIpAddress, endIPAddress));
|
||||
} else {
|
||||
whoisInformation.getNetwork().add(inetnum);
|
||||
}
|
||||
|
||||
logger.info("Network:" + whoisInformation.getNetwork().toString());
|
||||
whoisInformation.setNetworkInformation(new NetworkInformation(netname, descr, country));
|
||||
|
||||
break;
|
||||
case "route:":
|
||||
// get information on level-2 network
|
||||
String route = getValue("route:", valueMap);
|
||||
/*
|
||||
try {
|
||||
route = StringUtil.getValueBetweenKeywords(block, "route:", "descr:");
|
||||
} catch (ParseException ex) {
|
||||
throw new WhoisException ("Error while reading route information: "+ex.getMessage(), ex);
|
||||
}
|
||||
*/
|
||||
whoisInformation.getRootNetwork().add(route);
|
||||
logger.info("Root network " + whoisInformation.getRootNetwork().toString());
|
||||
break;
|
||||
|
||||
|
||||
case "role:":
|
||||
// admin company of network server belongs to
|
||||
logger.info("Skipping role block");
|
||||
break;
|
||||
case "person:":
|
||||
// admin person of network server belongs to
|
||||
logger.info("Skipping person block");
|
||||
break;
|
||||
case "% Information":
|
||||
case "% Note:":
|
||||
case "% This":
|
||||
case "%":
|
||||
logger.info("Skipping comment block");
|
||||
break;
|
||||
default:
|
||||
logger.info("Unknown block found");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -31,6 +31,11 @@ public class NetworkInformation implements Serializable {
|
||||
this.maintainedBy = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.netname+", "+this.country;
|
||||
}
|
||||
|
||||
/* *** getter / setter *** */
|
||||
/**
|
||||
* @return the netname
|
||||
|
||||
@ -1,18 +1,11 @@
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.ParseException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.net.whois.WhoisClient;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
* @author joern@muehlencord.de
|
||||
*/
|
||||
public class Whois {
|
||||
|
||||
@ -21,138 +14,48 @@ public class Whois {
|
||||
/** whois client from commons-net package to execute commands with */
|
||||
WhoisClient whois;
|
||||
/** the complete output */
|
||||
String whoIsString = null;
|
||||
/** network list in CIDR form the host belongs to */
|
||||
private List<String> network;
|
||||
/** network list in CIDDR form network belongs to */
|
||||
private List<String> rootNetwork;
|
||||
/** network information of host */
|
||||
private NetworkInformation networkInformation;
|
||||
String whoisString = null;
|
||||
|
||||
/**
|
||||
* creates a new instance of the whois client
|
||||
*/
|
||||
public Whois() {
|
||||
whois = new WhoisClient();
|
||||
whois.setDefaultTimeout(60000);
|
||||
network = null;
|
||||
rootNetwork = new LinkedList<>();
|
||||
networkInformation = null;
|
||||
|
||||
}
|
||||
|
||||
public void execute(String whoIsServer, String ip) throws UnknownHostException, SocketException, IOException, ParseException {
|
||||
/**
|
||||
* reads and parses the inforomation for the given ip address from the given whoisserver
|
||||
* @param whoIsServer the whois server to use
|
||||
* @param ip the ip to query whois data for
|
||||
* @return whoisInformation parsed from whois string
|
||||
* @throws WhoisException if the parsing fails
|
||||
*/
|
||||
public WhoisInformation execute(String whoIsServer, String ip) throws WhoisException {
|
||||
|
||||
String parameter = "";
|
||||
if (whoIsServer.equals("whois.arin.net")) {
|
||||
parameter = "n + ";
|
||||
}
|
||||
|
||||
// get whois information
|
||||
try {
|
||||
whois.connect(whoIsServer);
|
||||
whoIsString = whois.query(ip);
|
||||
// split by blank lines to identify blocks
|
||||
String[] blocks = whoIsString.split("\n\n");
|
||||
for (String block : blocks) {
|
||||
analyseBlock(block);
|
||||
}
|
||||
whoisString = whois.query(parameter + ip);
|
||||
whois.disconnect();
|
||||
} catch (Exception ex) {
|
||||
throw new WhoisException("Error while reading whois data from " + whoIsServer + ". Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
// TODO introduce parer per RIR
|
||||
private void analyseBlock(String block) throws ParseException {
|
||||
logger.debug("Start analysing block");
|
||||
logger.debug("\n---\n" + block + "\n---\n");
|
||||
|
||||
if ((block == null) || (block.equals("")) || (!block.contains(" "))) {
|
||||
logger.debug("Skippig empty block");
|
||||
return;
|
||||
}
|
||||
|
||||
String startString = block.substring(0, block.indexOf(" "));
|
||||
if (startString.equals("%")) {
|
||||
startString = block.substring(0, block.indexOf(" ", 2));
|
||||
}
|
||||
|
||||
switch (startString) {
|
||||
|
||||
case "inetnum:":
|
||||
|
||||
String inetnum = null;
|
||||
String country = null;
|
||||
String netname = null;
|
||||
String descr = null;
|
||||
String[] lines = block.split ("\n");
|
||||
for (String line : lines) {
|
||||
String lineStartString;
|
||||
String value;
|
||||
if (line.indexOf (" ") == -1) {
|
||||
lineStartString = line;
|
||||
value = "";
|
||||
// identify RIR and select correct parser
|
||||
WhoisParser parser;
|
||||
if (whoisString.toLowerCase().contains("arin.net")) {
|
||||
parser = new ArinWhoisParser();
|
||||
} else {
|
||||
lineStartString = line.substring(0, line.indexOf(" "));
|
||||
value = line.substring(line.indexOf(" "));
|
||||
value = value.trim();
|
||||
parser = new DefaultWhoisParser();
|
||||
}
|
||||
|
||||
switch (lineStartString) {
|
||||
case "inetnum:":
|
||||
inetnum = value;
|
||||
break;
|
||||
case "country:":
|
||||
country = value;
|
||||
break;
|
||||
case "descr":
|
||||
descr = value;
|
||||
break;
|
||||
case "netname":
|
||||
netname = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (inetnum == null) {
|
||||
inetnum = ""; // FIXME throw exception
|
||||
}
|
||||
// convert inetnum to CDIR
|
||||
String[] ipAddresses = inetnum.split(" "); // TODO - what happens if not 3 parts are found
|
||||
// FIXME add CDIR notation support
|
||||
String startIpAddress = ipAddresses[0];
|
||||
String endIPAddress = ipAddresses[2];
|
||||
network = CidrTool.rangeToCidrList(startIpAddress, endIPAddress);
|
||||
logger.info("Network:" + network.toString());
|
||||
|
||||
this.networkInformation = new NetworkInformation(netname, descr, country);
|
||||
|
||||
break;
|
||||
case "route:":
|
||||
// get information on level-2 network
|
||||
String route = StringUtil.getValueBetweenKeywords(block, "route:", "descr:");
|
||||
this.rootNetwork.add (route);
|
||||
logger.info ("Root network "+this.rootNetwork.toString());
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case "role:":
|
||||
// admin company of network server belongs to
|
||||
logger.info("Skipping role block");
|
||||
break;
|
||||
case "person:":
|
||||
// admin person of network server belongs to
|
||||
logger.info("Skipping person block");
|
||||
break;
|
||||
case "% Information":
|
||||
case "% Note:":
|
||||
case "% This":
|
||||
case "%":
|
||||
logger.info("Skipping comment block");
|
||||
break;
|
||||
default:
|
||||
logger.info("Unknown block found");
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getNetwork() {
|
||||
return this.network;
|
||||
}
|
||||
|
||||
public List<String> getRootNetwork() {
|
||||
return this.rootNetwork;
|
||||
}
|
||||
|
||||
public NetworkInformation getNetworkInformation() {
|
||||
return this.networkInformation;
|
||||
return parser.parseWhoIsString(whoisString);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
public class WhoisException extends Exception {
|
||||
|
||||
/**
|
||||
* Creates a new instance of
|
||||
* <code>WhoisException</code> without detail message.
|
||||
*/
|
||||
public WhoisException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of
|
||||
* <code>WhoisException</code> with the specified detail message.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public WhoisException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of
|
||||
* <code>WhoisException</code> with the specified detail message.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param th the root cause of this exception
|
||||
*/
|
||||
public WhoisException(String msg, Throwable th) {
|
||||
super(msg, th);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
*/
|
||||
public class WhoisInformation {
|
||||
|
||||
/** network list in CIDR form the host belongs to */
|
||||
private List<String> network;
|
||||
/** network list in CIDDR form network belongs to */
|
||||
private List<String> rootNetwork;
|
||||
/** network information of host */
|
||||
private NetworkInformation networkInformation;
|
||||
|
||||
public WhoisInformation() {
|
||||
network = new LinkedList<>();
|
||||
rootNetwork = new LinkedList<>();
|
||||
networkInformation = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the network
|
||||
*/
|
||||
public List<String> getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param network the network to set
|
||||
*/
|
||||
public void setNetwork(List<String> network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rootNetwork
|
||||
*/
|
||||
public List<String> getRootNetwork() {
|
||||
return rootNetwork;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rootNetwork the rootNetwork to set
|
||||
*/
|
||||
public void setRootNetwork(List<String> rootNetwork) {
|
||||
this.rootNetwork = rootNetwork;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the networkInformation
|
||||
*/
|
||||
public NetworkInformation getNetworkInformation() {
|
||||
return networkInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param networkInformation the networkInformation to set
|
||||
*/
|
||||
public void setNetworkInformation(NetworkInformation networkInformation) {
|
||||
this.networkInformation = networkInformation;
|
||||
}
|
||||
|
||||
void validate() throws WhoisException {
|
||||
if (network.isEmpty()) {
|
||||
throw new WhoisException("no network information found");
|
||||
}
|
||||
if (networkInformation == null) {
|
||||
throw new WhoisException("network information not set");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
public interface WhoisParser {
|
||||
|
||||
WhoisInformation parseWhoIsString(String whoIsString) throws WhoisException;
|
||||
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
public class ArinWhoisParserTest extends BaseTest {
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testParseArinIp() throws IOException, WhoisException {
|
||||
String whoisInformation = this.readContentFromFile("204.232.209.184.txt");
|
||||
ArinWhoisParser parser = new ArinWhoisParser();
|
||||
WhoisInformation information = parser.parseWhoIsString(whoisInformation);
|
||||
assertNotNull (information);
|
||||
information.validate();
|
||||
System.out.println ("testParseArinIp");
|
||||
System.out.println (information.getNetworkInformation().toString());
|
||||
System.out.println (information.getNetwork().toString());
|
||||
System.out.println (information.getRootNetwork().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseArinDoubleIp() throws IOException, WhoisException {
|
||||
String whoisInformation = this.readContentFromFile("108.166.92.167.txt");
|
||||
ArinWhoisParser parser = new ArinWhoisParser();
|
||||
WhoisInformation information = parser.parseWhoIsString(whoisInformation);
|
||||
assertNotNull (information);
|
||||
information.validate();
|
||||
System.out.println ("testParseArinDoubleIp");
|
||||
System.out.println (information.getNetworkInformation().toString());
|
||||
System.out.println (information.getNetwork().toString());
|
||||
System.out.println (information.getRootNetwork().toString());
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,8 @@
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.junit.BeforeClass;
|
||||
@ -19,4 +22,27 @@ public class BaseTest {
|
||||
PropertyConfigurator.configure(defaultConfigUrl);
|
||||
}
|
||||
|
||||
public String readContentFromFile(String name) throws IOException {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte[] buffer = new byte[4096];
|
||||
|
||||
if (BaseTest.class.getResourceAsStream(name) == null) {
|
||||
throw new IOException("File " + name + " not found");
|
||||
}
|
||||
|
||||
try (InputStream is = BaseTest.class.getResourceAsStream(name);
|
||||
BufferedInputStream bis = new BufferedInputStream(is);) {
|
||||
int bytesRead = 0;
|
||||
while (bytesRead != -1) {
|
||||
bytesRead = bis.read(buffer);
|
||||
if (bytesRead != -1) {
|
||||
sb.append(new String(buffer, 0, bytesRead));
|
||||
}
|
||||
}
|
||||
bis.close();
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,10 +4,6 @@
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.ParseException;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
@ -21,7 +17,7 @@ public class WhoisTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testDenicWhoIs() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||
public void testDenicWhoIs() throws WhoisException {
|
||||
Whois whoIsClient = new Whois();
|
||||
// Denic answers "status: connect" only
|
||||
whoIsClient.execute ("whois.denic.de", "-T dn,ace muehlencord.de");
|
||||
@ -29,30 +25,39 @@ public class WhoisTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testInternic() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||
public void testInternic() throws WhoisException {
|
||||
Whois whoIsClient = new Whois();
|
||||
whoIsClient.execute ("whois.1api.net", "egameladder.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // FIXME special parser for Arin needed
|
||||
@Ignore
|
||||
// TODO 184.173.67.10 whois with referal
|
||||
public void testArin() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||
public void testArin() throws WhoisException {
|
||||
Whois whoIsClient = new Whois();
|
||||
whoIsClient.execute ("whois.arin.net", "204.232.209.184");
|
||||
assertNotNull (whoIsClient.getNetworkInformation());
|
||||
WhoisInformation whoisInformation = whoIsClient.execute ("whois.arin.net", "204.232.209.184");
|
||||
assertNotNull (whoisInformation);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testApnic() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||
public void testApnic() throws WhoisException {
|
||||
Whois whoIsClient = new Whois();
|
||||
whoIsClient.execute ("whois.apnic.net", "60.247.69.45");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLacnic() throws WhoisException {
|
||||
Whois whoIsClient = new Whois();
|
||||
WhoisInformation whoisInformation = whoIsClient.execute ("whois.lacnic.net", "200.29.132.82");
|
||||
assertNotNull (whoisInformation);
|
||||
assertEquals ("Country", "CL", whoisInformation.getNetworkInformation().getCountry());
|
||||
assertTrue ("Network", whoisInformation.getNetwork().contains("200.29.132.80/29"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testUnkown() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||
public void testUnkown() throws WhoisException {
|
||||
Whois whoIsClient = new Whois();
|
||||
// whoIsClient.execute("whois.arin.net", "174.139.180.10");
|
||||
// whoIsClient.execute("whois.twnic.net", "60.250.38.39");
|
||||
@ -66,11 +71,11 @@ public class WhoisTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testStepWise() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||
public void testStepWise() throws WhoisException {
|
||||
Whois whoIsClient = new Whois();
|
||||
// whoIsClient.execute ("whois.ripe.net", "88.198.181.181");
|
||||
whoIsClient.execute ("whois.ripe.net", "212.204.60.1");
|
||||
assertTrue ("network", whoIsClient.getNetwork().contains("212.204.60.0/24"));
|
||||
WhoisInformation whoisInformation = whoIsClient.execute ("whois.ripe.net", "212.204.60.1");
|
||||
assertTrue ("network", whoisInformation.getNetwork().contains("212.204.60.0/24"));
|
||||
// whoIsClient.execute ("whois.ripe.net", "212.204.60.0");
|
||||
// whoIsClient.execute ("whois.ripe.net", "212.0.0.0/8");
|
||||
}
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
|
||||
#
|
||||
# ARIN WHOIS data and services are subject to the Terms of Use
|
||||
# available at: https://www.arin.net/whois_tou.html
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# The following results may also be obtained via:
|
||||
# http://whois.arin.net/rest/nets;q=108.166.92.167?showDetails=true&showARIN=false&ext=netref2
|
||||
#
|
||||
|
||||
|
||||
# start
|
||||
|
||||
NetRange: 108.166.80.0 - 108.166.95.255
|
||||
CIDR: 108.166.80.0/20
|
||||
OriginAS:
|
||||
NetName: RACKS-8-1329149534802189
|
||||
NetHandle: NET-108-166-80-0-1
|
||||
Parent: NET-108-166-0-0-1
|
||||
NetType: Reassigned
|
||||
RegDate: 2012-02-13
|
||||
Updated: 2012-02-13
|
||||
Ref: http://whois.arin.net/rest/net/NET-108-166-80-0-1
|
||||
|
||||
CustName: Slicehost
|
||||
Address: 5000 Walzem Rd.
|
||||
City: San Antonio
|
||||
StateProv: TX
|
||||
PostalCode: 78229
|
||||
Country: US
|
||||
RegDate: 2012-02-13
|
||||
Updated: 2012-02-13
|
||||
Ref: http://whois.arin.net/rest/customer/C02931699
|
||||
|
||||
OrgAbuseHandle: ABUSE45-ARIN
|
||||
OrgAbuseName: Abuse Desk
|
||||
OrgAbusePhone: +1-210-892-4000
|
||||
OrgAbuseEmail: abuse@rackspace.com
|
||||
OrgAbuseRef: http://whois.arin.net/rest/poc/ABUSE45-ARIN
|
||||
|
||||
OrgTechHandle: IPADM17-ARIN
|
||||
OrgTechName: IPADMIN
|
||||
OrgTechPhone: +1-210-892-4000
|
||||
OrgTechEmail: hostmaster@rackspace.com
|
||||
OrgTechRef: http://whois.arin.net/rest/poc/IPADM17-ARIN
|
||||
|
||||
# end
|
||||
|
||||
|
||||
# start
|
||||
|
||||
NetRange: 108.166.0.0 - 108.166.127.255
|
||||
CIDR: 108.166.0.0/17
|
||||
OriginAS: AS19994
|
||||
NetName: RACKS-8-NET-5
|
||||
NetHandle: NET-108-166-0-0-1
|
||||
Parent: NET-108-0-0-0-0
|
||||
NetType: Direct Allocation
|
||||
RegDate: 2011-12-06
|
||||
Updated: 2011-12-06
|
||||
Ref: http://whois.arin.net/rest/net/NET-108-166-0-0-1
|
||||
|
||||
OrgName: Rackspace Hosting
|
||||
OrgId: RACKS-8
|
||||
Address: 5000 Walzem Road
|
||||
City: San Antonio
|
||||
StateProv: TX
|
||||
PostalCode: 78218
|
||||
Country: US
|
||||
RegDate: 2010-03-29
|
||||
Updated: 2011-11-30
|
||||
Ref: http://whois.arin.net/rest/org/RACKS-8
|
||||
|
||||
OrgAbuseHandle: ABUSE45-ARIN
|
||||
OrgAbuseName: Abuse Desk
|
||||
OrgAbusePhone: +1-210-892-4000
|
||||
OrgAbuseEmail: abuse@rackspace.com
|
||||
OrgAbuseRef: http://whois.arin.net/rest/poc/ABUSE45-ARIN
|
||||
|
||||
OrgTechHandle: IPADM17-ARIN
|
||||
OrgTechName: IPADMIN
|
||||
OrgTechPhone: +1-210-892-4000
|
||||
OrgTechEmail: hostmaster@rackspace.com
|
||||
OrgTechRef: http://whois.arin.net/rest/poc/IPADM17-ARIN
|
||||
|
||||
# end
|
||||
|
||||
|
||||
|
||||
#
|
||||
# ARIN WHOIS data and services are subject to the Terms of Use
|
||||
# available at: https://www.arin.net/whois_tou.html
|
||||
#
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
|
||||
% Joint Whois - whois.lacnic.net
|
||||
% This server accepts single ASN, IPv4 or IPv6 queries
|
||||
|
||||
% LACNIC resource: whois.lacnic.net
|
||||
|
||||
|
||||
% Copyright LACNIC lacnic.net
|
||||
% The data below is provided for information purposes
|
||||
% and to assist persons in obtaining information about or
|
||||
% related to AS and IP numbers registrations
|
||||
% By submitting a whois query, you agree to use this data
|
||||
% only for lawful purposes.
|
||||
% 2013-04-14 11:27:07 (BRT -03:00)
|
||||
|
||||
inetnum: 200.29.132.80/29
|
||||
status: reallocated
|
||||
owner: Promet Servicios S.A.
|
||||
ownerid: CL-PSSA3-LACNIC
|
||||
responsible: Promet Servicios S.A.
|
||||
address: Rinconada El Salto, 202, Huechuraba
|
||||
address: NONE - Santiago - RM
|
||||
country: CL
|
||||
phone: +56 2 5825000 []
|
||||
owner-c: AIC2
|
||||
tech-c: AIC2
|
||||
abuse-c: AIC2
|
||||
created: 20090310
|
||||
changed: 20090310
|
||||
inetnum-up: 200.29.128/19
|
||||
|
||||
nic-hdl: AIC2
|
||||
person: Core Internet Telmex Chile
|
||||
e-mail: netadmin@IP.TELMEXCHILE.CL
|
||||
address: Rinconada el Salto, 202, Huechuraba
|
||||
address: -- - Santiago -
|
||||
country: CL
|
||||
phone: +56 2 5825365 []
|
||||
created: 20030314
|
||||
changed: 20070417
|
||||
|
||||
% whois.lacnic.net accepts only direct match queries.
|
||||
% Types of queries are: POCs, ownerid, CIDR blocks, IP
|
||||
% and AS numbers.
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
# ARIN WHOIS data and services are subject to the Terms of Use
|
||||
# available at: https://www.arin.net/whois_tou.html
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# The following results may also be obtained via:
|
||||
# http://whois.arin.net/rest/nets;q=204.232.209.184?showDetails=true&showARIN=false&ext=netref2
|
||||
#
|
||||
|
||||
NetRange: 204.232.128.0 - 204.232.255.255
|
||||
CIDR: 204.232.128.0/17
|
||||
OriginAS: AS33070, AS10532, AS19994, AS27357
|
||||
NetName: RSCP-NET-4
|
||||
NetHandle: NET-204-232-128-0-1
|
||||
Parent: NET-204-0-0-0-0
|
||||
NetType: Direct Allocation
|
||||
RegDate: 2009-06-24
|
||||
Updated: 2012-02-24
|
||||
Ref: http://whois.arin.net/rest/net/NET-204-232-128-0-1
|
||||
|
||||
OrgName: Rackspace Hosting
|
||||
OrgId: RACKS-8
|
||||
Address: 5000 Walzem Road
|
||||
City: San Antonio
|
||||
StateProv: TX
|
||||
PostalCode: 78218
|
||||
Country: US
|
||||
RegDate: 2010-03-29
|
||||
Updated: 2011-11-30
|
||||
Ref: http://whois.arin.net/rest/org/RACKS-8
|
||||
|
||||
OrgAbuseHandle: ABUSE45-ARIN
|
||||
OrgAbuseName: Abuse Desk
|
||||
OrgAbusePhone: +1-210-892-4000
|
||||
OrgAbuseEmail: abuse@rackspace.com
|
||||
OrgAbuseRef: http://whois.arin.net/rest/poc/ABUSE45-ARIN
|
||||
|
||||
OrgTechHandle: IPADM17-ARIN
|
||||
OrgTechName: IPADMIN
|
||||
OrgTechPhone: +1-210-892-4000
|
||||
OrgTechEmail: hostmaster@rackspace.com
|
||||
OrgTechRef: http://whois.arin.net/rest/poc/IPADM17-ARIN
|
||||
|
||||
|
||||
#
|
||||
# ARIN WHOIS data and services are subject to the Terms of Use
|
||||
# available at: https://www.arin.net/whois_tou.html
|
||||
#
|
||||
@ -0,0 +1,17 @@
|
||||
|
||||
#
|
||||
# ARIN WHOIS data and services are subject to the Terms of Use
|
||||
# available at: https://www.arin.net/whois_tou.html
|
||||
#
|
||||
|
||||
|
||||
No match found for n + 64.185.229.236.
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# ARIN WHOIS data and services are subject to the Terms of Use
|
||||
# available at: https://www.arin.net/whois_tou.html
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user