improved WhoIsParser
This commit is contained in:
@ -22,13 +22,6 @@
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
@ -47,6 +40,11 @@
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.muehlencord.shared</groupId>
|
||||
<artifactId>shared-util</artifactId>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package de.muehlencord.shared.network.whois;
|
||||
|
||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -69,9 +70,9 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
|
||||
// FIXME add CDIR notation support
|
||||
String startIpAddress = ipAddresses[0];
|
||||
String endIPAddress = ipAddresses[2];
|
||||
whoisInformation.getNetwork().addAll(rangeToCidrList(startIpAddress, endIPAddress));
|
||||
whoisInformation.addNetwork(rangeToCidrList(startIpAddress, endIPAddress));
|
||||
} else {
|
||||
whoisInformation.getNetwork().add(inetnum);
|
||||
whoisInformation.addNetwork(inetnum);
|
||||
}
|
||||
|
||||
LOGGER.info("Network:" + whoisInformation.getNetwork().toString());
|
||||
@ -88,7 +89,7 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
|
||||
throw new WhoisException ("Error while reading route information: "+ex.getMessage(), ex);
|
||||
}
|
||||
*/
|
||||
whoisInformation.getRootNetwork().add(route);
|
||||
whoisInformation.addRootNetwork(route);
|
||||
LOGGER.info("Root network " + whoisInformation.getRootNetwork().toString());
|
||||
break;
|
||||
|
||||
@ -109,6 +110,7 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
|
||||
break;
|
||||
default:
|
||||
LOGGER.info("Unknown block found");
|
||||
LOGGER.error(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,11 +10,17 @@ import java.util.List;
|
||||
*/
|
||||
public class WhoisInformation {
|
||||
|
||||
/** network list in CIDR form the host belongs to */
|
||||
/**
|
||||
* network list in CIDR form the host belongs to
|
||||
*/
|
||||
private List<String> network;
|
||||
/** network list in CIDDR form network belongs to */
|
||||
/**
|
||||
* network list in CIDDR form network belongs to
|
||||
*/
|
||||
private List<String> rootNetwork;
|
||||
/** network information of host */
|
||||
/**
|
||||
* network information of host
|
||||
*/
|
||||
private NetworkInformation networkInformation;
|
||||
|
||||
public WhoisInformation() {
|
||||
@ -28,7 +34,11 @@ public class WhoisInformation {
|
||||
* @return the network
|
||||
*/
|
||||
public List<String> getNetwork() {
|
||||
return new ArrayList<>(network);
|
||||
return new ArrayList<>(network);
|
||||
}
|
||||
|
||||
public void addNetwork(List<String> network) {
|
||||
this.network.addAll(new ArrayList<>(network));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,11 +48,20 @@ public class WhoisInformation {
|
||||
this.network = new ArrayList<>(network);
|
||||
}
|
||||
|
||||
/**
|
||||
* add a new network to the list of existing networks
|
||||
*
|
||||
* @param network the new network to add
|
||||
*/
|
||||
public void addNetwork(String network) {
|
||||
this.network.add(network);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rootNetwork
|
||||
*/
|
||||
public List<String> getRootNetwork() {
|
||||
return new ArrayList<>(rootNetwork);
|
||||
return new ArrayList<>(rootNetwork);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,6 +70,10 @@ public class WhoisInformation {
|
||||
public void setRootNetwork(List<String> rootNetwork) {
|
||||
this.rootNetwork = new ArrayList<>(rootNetwork);
|
||||
}
|
||||
|
||||
public void addRootNetwork (String rootNetwork) {
|
||||
this.rootNetwork.add (rootNetwork);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the networkInformation
|
||||
|
||||
@ -2,6 +2,7 @@ package de.muehlencord.shared.network.whois;
|
||||
|
||||
import de.muehlencord.shared.network.BaseTest;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Ignore;
|
||||
@ -74,6 +75,19 @@ public class WhoisTest extends BaseTest {
|
||||
whoIsClient.execute("whois.arin.net", "32.64.68.229");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneric() throws WhoisException {
|
||||
Whois whoIsClient = new Whois();
|
||||
WhoisInformation info = whoIsClient.execute("whois.ripe.net", "185.125.4.210");
|
||||
assertNotNull (info);
|
||||
assertNotNull (info.getNetwork());
|
||||
assertFalse (info.getNetwork().isEmpty());
|
||||
System.out.println (info.getNetwork().toString());
|
||||
System.out.println (info.getRootNetwork().toString());
|
||||
System.out.println (info.getNetworkInformation().getDescription());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
|
||||
33
network/src/test/resources/log4j.xml
Normal file
33
network/src/test/resources/log4j.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
||||
debug="true">
|
||||
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<category name="de.muehlencord">
|
||||
<priority value="DEBUG"/>
|
||||
</category>
|
||||
|
||||
<category name="com.sun">
|
||||
<priority value="WARN"/>
|
||||
</category>
|
||||
|
||||
<category name="javax.xml">
|
||||
<priority value="WARN"/>
|
||||
</category>
|
||||
|
||||
<category name="org.apache.commons">
|
||||
<priority value="WARN"/>
|
||||
</category>
|
||||
|
||||
|
||||
<root>
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="consoleAppender" />
|
||||
</root>
|
||||
</log4j:configuration>
|
||||
Reference in New Issue
Block a user