imporived Whois
This commit is contained in:
@ -4,11 +4,13 @@
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jomu
|
||||
*/
|
||||
public class NetworkInformation {
|
||||
public class NetworkInformation implements Serializable {
|
||||
|
||||
// private String network;
|
||||
private String netname;
|
||||
|
||||
@ -32,6 +32,9 @@ public class Whois {
|
||||
public Whois() {
|
||||
whois = new WhoisClient();
|
||||
whois.setDefaultTimeout(60000);
|
||||
network = null;
|
||||
rootNetwork = new LinkedList<>();
|
||||
networkInformation = null;
|
||||
|
||||
}
|
||||
|
||||
@ -64,30 +67,50 @@ public class Whois {
|
||||
switch (startString) {
|
||||
|
||||
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
|
||||
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);
|
||||
network = CidrTool.rangeToCidrList(startIpAddress, endIPAddress);
|
||||
logger.info("Network:" + network.toString());
|
||||
|
||||
this.networkInformation = new NetworkInformation(netname, descr, country);
|
||||
@ -95,9 +118,8 @@ public class Whois {
|
||||
break;
|
||||
case "route:":
|
||||
// get information on level-2 network
|
||||
String route = StringUtil.getValueBetweenKeywords(block, "route:", "descr:");
|
||||
this.rootNetwork = new LinkedList<>();
|
||||
this.rootNetwork.add(route);
|
||||
String route = StringUtil.getValueBetweenKeywords(block, "route:", "descr:");
|
||||
this.rootNetwork.add (route);
|
||||
logger.info ("Root network "+this.rootNetwork.toString());
|
||||
break;
|
||||
|
||||
@ -129,4 +151,8 @@ public class Whois {
|
||||
public List<String> getRootNetwork() {
|
||||
return this.rootNetwork;
|
||||
}
|
||||
|
||||
public NetworkInformation getNetworkInformation() {
|
||||
return this.networkInformation;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user