From 9785326a1d25efff2d5d507d56a3be06f499101c Mon Sep 17 00:00:00 2001 From: jomu Date: Sun, 14 Apr 2013 15:27:02 +0000 Subject: [PATCH] improved Whois parsing --- .../shared/network/AbstractWhoisParser.java | 45 +++++ .../shared/network/ArinWhoisParser.java | 130 ++++++++++++++ .../shared/network/DefaultWhoisParser.java | 119 +++++++++++++ .../shared/network/NetworkInformation.java | 5 + .../de/muehlencord/shared/network/Whois.java | 163 ++++-------------- .../shared/network/WhoisException.java | 40 +++++ .../shared/network/WhoisInformation.java | 76 ++++++++ .../shared/network/WhoisParser.java | 15 ++ .../shared/network/ArinWhoisParserTest.java | 45 +++++ .../muehlencord/shared/network/BaseTest.java | 32 +++- .../muehlencord/shared/network/WhoisTest.java | 35 ++-- .../shared/network/108.166.92.167.txt | 96 +++++++++++ .../shared/network/200.29.132.82.txt | 45 +++++ .../shared/network/204.232.209.184.txt | 49 ++++++ .../shared/network/64.185.229.236.txt | 17 ++ 15 files changed, 764 insertions(+), 148 deletions(-) create mode 100644 network/src/main/java/de/muehlencord/shared/network/AbstractWhoisParser.java create mode 100644 network/src/main/java/de/muehlencord/shared/network/ArinWhoisParser.java create mode 100644 network/src/main/java/de/muehlencord/shared/network/DefaultWhoisParser.java create mode 100644 network/src/main/java/de/muehlencord/shared/network/WhoisException.java create mode 100644 network/src/main/java/de/muehlencord/shared/network/WhoisInformation.java create mode 100644 network/src/main/java/de/muehlencord/shared/network/WhoisParser.java create mode 100644 network/src/test/java/de/muehlencord/shared/network/ArinWhoisParserTest.java create mode 100644 network/src/test/resources/de/muehlencord/shared/network/108.166.92.167.txt create mode 100644 network/src/test/resources/de/muehlencord/shared/network/200.29.132.82.txt create mode 100644 network/src/test/resources/de/muehlencord/shared/network/204.232.209.184.txt create mode 100644 network/src/test/resources/de/muehlencord/shared/network/64.185.229.236.txt diff --git a/network/src/main/java/de/muehlencord/shared/network/AbstractWhoisParser.java b/network/src/main/java/de/muehlencord/shared/network/AbstractWhoisParser.java new file mode 100644 index 0000000..d20ad43 --- /dev/null +++ b/network/src/main/java/de/muehlencord/shared/network/AbstractWhoisParser.java @@ -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 getValueMap(String blockString) { + Map 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 valueMap) { + if (valueMap.containsKey(key)) { + return valueMap.get(key); + } else { + return null; + } + } +} diff --git a/network/src/main/java/de/muehlencord/shared/network/ArinWhoisParser.java b/network/src/main/java/de/muehlencord/shared/network/ArinWhoisParser.java new file mode 100644 index 0000000..d8aa062 --- /dev/null +++ b/network/src/main/java/de/muehlencord/shared/network/ArinWhoisParser.java @@ -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 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"); + } + } +} diff --git a/network/src/main/java/de/muehlencord/shared/network/DefaultWhoisParser.java b/network/src/main/java/de/muehlencord/shared/network/DefaultWhoisParser.java new file mode 100644 index 0000000..0e7395c --- /dev/null +++ b/network/src/main/java/de/muehlencord/shared/network/DefaultWhoisParser.java @@ -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 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"); + } + } +} diff --git a/network/src/main/java/de/muehlencord/shared/network/NetworkInformation.java b/network/src/main/java/de/muehlencord/shared/network/NetworkInformation.java index d89f4b1..d240e50 100644 --- a/network/src/main/java/de/muehlencord/shared/network/NetworkInformation.java +++ b/network/src/main/java/de/muehlencord/shared/network/NetworkInformation.java @@ -30,6 +30,11 @@ public class NetworkInformation implements Serializable { this.status = null; this.maintainedBy = null; } + + @Override + public String toString() { + return this.netname+", "+this.country; + } /* *** getter / setter *** */ /** diff --git a/network/src/main/java/de/muehlencord/shared/network/Whois.java b/network/src/main/java/de/muehlencord/shared/network/Whois.java index feb4bae..9668ed3 100644 --- a/network/src/main/java/de/muehlencord/shared/network/Whois.java +++ b/network/src/main/java/de/muehlencord/shared/network/Whois.java @@ -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 network; - /** network list in CIDDR form network belongs to */ - private List 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 { - 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); - } - whois.disconnect(); - } - - // 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; + /** + * 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 + "; } - String startString = block.substring(0, block.indexOf(" ")); - if (startString.equals("%")) { - startString = block.substring(0, block.indexOf(" ", 2)); + // get whois information + try { + whois.connect(whoIsServer); + whoisString = whois.query(parameter + ip); + whois.disconnect(); + } catch (Exception ex) { + throw new WhoisException("Error while reading whois data from " + whoIsServer + ". Reason: " + ex.getMessage(), ex); } - 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 = ""; - } else { - lineStartString = line.substring(0, line.indexOf(" ")); - value = line.substring(line.indexOf(" ")); - value = value.trim(); - } - - 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"); + // identify RIR and select correct parser + WhoisParser parser; + if (whoisString.toLowerCase().contains("arin.net")) { + parser = new ArinWhoisParser(); + } else { + parser = new DefaultWhoisParser(); } - } - public List getNetwork() { - return this.network; - } - - public List getRootNetwork() { - return this.rootNetwork; - } - - public NetworkInformation getNetworkInformation() { - return this.networkInformation; + return parser.parseWhoIsString(whoisString); + } } diff --git a/network/src/main/java/de/muehlencord/shared/network/WhoisException.java b/network/src/main/java/de/muehlencord/shared/network/WhoisException.java new file mode 100644 index 0000000..9ad5487 --- /dev/null +++ b/network/src/main/java/de/muehlencord/shared/network/WhoisException.java @@ -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 + * WhoisException without detail message. + */ + public WhoisException() { + } + + /** + * Constructs an instance of + * WhoisException with the specified detail message. + * + * @param msg the detail message. + */ + public WhoisException(String msg) { + super(msg); + } + + /** + * Constructs an instance of + * WhoisException 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); + } +} diff --git a/network/src/main/java/de/muehlencord/shared/network/WhoisInformation.java b/network/src/main/java/de/muehlencord/shared/network/WhoisInformation.java new file mode 100644 index 0000000..287a384 --- /dev/null +++ b/network/src/main/java/de/muehlencord/shared/network/WhoisInformation.java @@ -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 network; + /** network list in CIDDR form network belongs to */ + private List rootNetwork; + /** network information of host */ + private NetworkInformation networkInformation; + + public WhoisInformation() { + network = new LinkedList<>(); + rootNetwork = new LinkedList<>(); + networkInformation = null; + + } + + /** + * @return the network + */ + public List getNetwork() { + return network; + } + + /** + * @param network the network to set + */ + public void setNetwork(List network) { + this.network = network; + } + + /** + * @return the rootNetwork + */ + public List getRootNetwork() { + return rootNetwork; + } + + /** + * @param rootNetwork the rootNetwork to set + */ + public void setRootNetwork(List 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"); + } + } +} diff --git a/network/src/main/java/de/muehlencord/shared/network/WhoisParser.java b/network/src/main/java/de/muehlencord/shared/network/WhoisParser.java new file mode 100644 index 0000000..cc943d0 --- /dev/null +++ b/network/src/main/java/de/muehlencord/shared/network/WhoisParser.java @@ -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; + +} diff --git a/network/src/test/java/de/muehlencord/shared/network/ArinWhoisParserTest.java b/network/src/test/java/de/muehlencord/shared/network/ArinWhoisParserTest.java new file mode 100644 index 0000000..e01da19 --- /dev/null +++ b/network/src/test/java/de/muehlencord/shared/network/ArinWhoisParserTest.java @@ -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()); + } +} \ No newline at end of file diff --git a/network/src/test/java/de/muehlencord/shared/network/BaseTest.java b/network/src/test/java/de/muehlencord/shared/network/BaseTest.java index 05a917a..3a25e83 100644 --- a/network/src/test/java/de/muehlencord/shared/network/BaseTest.java +++ b/network/src/test/java/de/muehlencord/shared/network/BaseTest.java @@ -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; @@ -9,8 +12,8 @@ import org.junit.BeforeClass; * @author joern@muehlencord.de */ public class BaseTest { - - /** + + /** * inits logging according to default setup in package */ @BeforeClass @@ -18,5 +21,28 @@ public class BaseTest { URL defaultConfigUrl = BaseTest.class.getResource("/logging.properties"); 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(); + } } diff --git a/network/src/test/java/de/muehlencord/shared/network/WhoisTest.java b/network/src/test/java/de/muehlencord/shared/network/WhoisTest.java index a74c513..9444bb2 100644 --- a/network/src/test/java/de/muehlencord/shared/network/WhoisTest.java +++ b/network/src/test/java/de/muehlencord/shared/network/WhoisTest.java @@ -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"); } diff --git a/network/src/test/resources/de/muehlencord/shared/network/108.166.92.167.txt b/network/src/test/resources/de/muehlencord/shared/network/108.166.92.167.txt new file mode 100644 index 0000000..1f11357 --- /dev/null +++ b/network/src/test/resources/de/muehlencord/shared/network/108.166.92.167.txt @@ -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 +# + diff --git a/network/src/test/resources/de/muehlencord/shared/network/200.29.132.82.txt b/network/src/test/resources/de/muehlencord/shared/network/200.29.132.82.txt new file mode 100644 index 0000000..3d9caed --- /dev/null +++ b/network/src/test/resources/de/muehlencord/shared/network/200.29.132.82.txt @@ -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. + diff --git a/network/src/test/resources/de/muehlencord/shared/network/204.232.209.184.txt b/network/src/test/resources/de/muehlencord/shared/network/204.232.209.184.txt new file mode 100644 index 0000000..dff67d7 --- /dev/null +++ b/network/src/test/resources/de/muehlencord/shared/network/204.232.209.184.txt @@ -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 +# \ No newline at end of file diff --git a/network/src/test/resources/de/muehlencord/shared/network/64.185.229.236.txt b/network/src/test/resources/de/muehlencord/shared/network/64.185.229.236.txt new file mode 100644 index 0000000..a54854b --- /dev/null +++ b/network/src/test/resources/de/muehlencord/shared/network/64.185.229.236.txt @@ -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 +# +