imporived Whois
This commit is contained in:
@ -4,11 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.network;
|
package de.muehlencord.shared.network;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jomu
|
* @author jomu
|
||||||
*/
|
*/
|
||||||
public class NetworkInformation {
|
public class NetworkInformation implements Serializable {
|
||||||
|
|
||||||
// private String network;
|
// private String network;
|
||||||
private String netname;
|
private String netname;
|
||||||
|
|||||||
@ -32,6 +32,9 @@ public class Whois {
|
|||||||
public Whois() {
|
public Whois() {
|
||||||
whois = new WhoisClient();
|
whois = new WhoisClient();
|
||||||
whois.setDefaultTimeout(60000);
|
whois.setDefaultTimeout(60000);
|
||||||
|
network = null;
|
||||||
|
rootNetwork = new LinkedList<>();
|
||||||
|
networkInformation = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,24 +67,44 @@ public class Whois {
|
|||||||
switch (startString) {
|
switch (startString) {
|
||||||
|
|
||||||
case "inetnum:":
|
case "inetnum:":
|
||||||
// information on network server belongs to (upper level / level -1)
|
|
||||||
String inetnum = StringUtil.getValueBetweenKeywords(block, "inetnum:", "netname:");
|
|
||||||
logger.info("inetnum: = " + inetnum);
|
|
||||||
String netname = StringUtil.getValueBetweenKeywords(block, "netname:", "descr:");
|
|
||||||
logger.info("netname: = " + netname);
|
|
||||||
String descr = StringUtil.getValueBetweenKeywords(block, "descr:", "country:");
|
|
||||||
logger.info("descr: = " + descr);
|
|
||||||
String country = StringUtil.getValueBetweenKeywords(block, "country:", "admin-c:");
|
|
||||||
logger.info("country: = " + country);
|
|
||||||
String adminC = StringUtil.getValueBetweenKeywords(block, "admin-c:", "tech-c:");
|
|
||||||
logger.info("admin-c: = " + adminC);
|
|
||||||
String techC = StringUtil.getValueBetweenKeywords(block, "tech-c:", "status:");
|
|
||||||
logger.info("tech-c: = " + techC);
|
|
||||||
String status = StringUtil.getValueBetweenKeywords(block, "status:", "mnt-by:");
|
|
||||||
logger.info("status: = " + status);
|
|
||||||
String mntBy = StringUtil.getValueBetweenKeywords(block, "mnt-by:", "source:");
|
|
||||||
logger.info("mnt-by: = " + mntBy);
|
|
||||||
|
|
||||||
|
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
|
// convert inetnum to CDIR
|
||||||
String[] ipAddresses = inetnum.split(" "); // TODO - what happens if not 3 parts are found
|
String[] ipAddresses = inetnum.split(" "); // TODO - what happens if not 3 parts are found
|
||||||
// FIXME add CDIR notation support
|
// FIXME add CDIR notation support
|
||||||
@ -96,8 +119,7 @@ public class Whois {
|
|||||||
case "route:":
|
case "route:":
|
||||||
// get information on level-2 network
|
// get information on level-2 network
|
||||||
String route = StringUtil.getValueBetweenKeywords(block, "route:", "descr:");
|
String route = StringUtil.getValueBetweenKeywords(block, "route:", "descr:");
|
||||||
this.rootNetwork = new LinkedList<>();
|
this.rootNetwork.add (route);
|
||||||
this.rootNetwork.add(route);
|
|
||||||
logger.info ("Root network "+this.rootNetwork.toString());
|
logger.info ("Root network "+this.rootNetwork.toString());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -129,4 +151,8 @@ public class Whois {
|
|||||||
public List<String> getRootNetwork() {
|
public List<String> getRootNetwork() {
|
||||||
return this.rootNetwork;
|
return this.rootNetwork;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NetworkInformation getNetworkInformation() {
|
||||||
|
return this.networkInformation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package de.muehlencord.shared.network;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jomu
|
||||||
|
*/
|
||||||
|
public class CidrToolTest {
|
||||||
|
|
||||||
|
public CidrToolTest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCidrConversion() {
|
||||||
|
System.out.println (CidrTool.rangeToCidrList("213.55.64.0", "213.55.127.255"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -31,11 +31,50 @@ public class WhoisTest extends BaseTest {
|
|||||||
@Ignore
|
@Ignore
|
||||||
public void testInternic() throws UnknownHostException, SocketException, IOException, ParseException {
|
public void testInternic() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||||
Whois whoIsClient = new Whois();
|
Whois whoIsClient = new Whois();
|
||||||
// Denic answers "status: connect" only
|
|
||||||
whoIsClient.execute ("whois.1api.net", "egameladder.com");
|
whoIsClient.execute ("whois.1api.net", "egameladder.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void testArin() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||||
|
Whois whoIsClient = new Whois();
|
||||||
|
whoIsClient.execute ("whois.arin.net", "204.232.209.184");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void testApnic() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||||
|
Whois whoIsClient = new Whois();
|
||||||
|
whoIsClient.execute ("whois.apnic.net", "60.247.69.45");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnkown() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||||
|
Whois whoIsClient = new Whois();
|
||||||
|
// whoIsClient.execute("whois.arin.net", "174.139.180.10");
|
||||||
|
// whoIsClient.execute("whois.twnic.net", "60.250.38.39");
|
||||||
|
// whoIsClient.execute("whois.apnic.net", "60.28.27.14");
|
||||||
|
// whoIsClient.execute("whois.apnic.net", "203.127.200.113");
|
||||||
|
// whoIsClient.execute("whois.apnic.net", "182.72.111.26");
|
||||||
|
// whoIsClient.execute("whois.ripe.net", "213.55.95.62"); // Transferred to Afrinic
|
||||||
|
whoIsClient.execute("whois.afrinic.net", "213.55.95.62");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testStepWise() throws UnknownHostException, SocketException, IOException, ParseException {
|
public void testStepWise() throws UnknownHostException, SocketException, IOException, ParseException {
|
||||||
Whois whoIsClient = new Whois();
|
Whois whoIsClient = new Whois();
|
||||||
// whoIsClient.execute ("whois.ripe.net", "88.198.181.181");
|
// whoIsClient.execute ("whois.ripe.net", "88.198.181.181");
|
||||||
@ -43,6 +82,5 @@ public class WhoisTest extends BaseTest {
|
|||||||
assertTrue ("network", whoIsClient.getNetwork().contains("212.204.60.0/24"));
|
assertTrue ("network", whoIsClient.getNetwork().contains("212.204.60.0/24"));
|
||||||
// whoIsClient.execute ("whois.ripe.net", "212.204.60.0");
|
// whoIsClient.execute ("whois.ripe.net", "212.204.60.0");
|
||||||
// whoIsClient.execute ("whois.ripe.net", "212.0.0.0/8");
|
// whoIsClient.execute ("whois.ripe.net", "212.0.0.0/8");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user