improved Whois parsing

This commit is contained in:
jomu
2013-04-14 15:27:02 +00:00
parent 923dba1c1b
commit 9785326a1d
15 changed files with 764 additions and 148 deletions

View File

@ -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());
}
}

View File

@ -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();
}
}

View File

@ -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");
}

View File

@ -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
#

View File

@ -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.

View File

@ -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
#

View File

@ -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
#