List of usage examples for org.apache.commons.net.whois WhoisClient query
public String query(String handle) throws IOException
From source file:examples.fwhois.java
public static final void main(String[] args) { int index;/*from w w w . j a va2s .co m*/ String handle, host; InetAddress address = null; WhoisClient whois; if (args.length != 1) { System.err.println("usage: fwhois handle[@<server>]"); System.exit(1); } index = args[0].lastIndexOf("@"); whois = new WhoisClient(); // We want to timeout if a response takes longer than 60 seconds whois.setDefaultTimeout(60000); if (index == -1) { handle = args[0]; host = WhoisClient.DEFAULT_HOST; } else { handle = args[0].substring(0, index); host = args[0].substring(index + 1); } try { address = InetAddress.getByName(host); } catch (UnknownHostException e) { System.err.println("Error unknown host: " + e.getMessage()); System.exit(1); } System.out.println("[" + address.getHostName() + "]"); try { whois.connect(address); System.out.print(whois.query(handle)); whois.disconnect(); } catch (IOException e) { System.err.println("Error I/O exception: " + e.getMessage()); System.exit(1); } }
From source file:examples.unix.fwhois.java
public static void main(String[] args) { int index;/*ww w.j a v a2s .co m*/ String handle, host; InetAddress address = null; WhoisClient whois; if (args.length != 1) { System.err.println("usage: fwhois handle[@<server>]"); System.exit(1); } index = args[0].lastIndexOf("@"); whois = new WhoisClient(); // We want to timeout if a response takes longer than 60 seconds whois.setDefaultTimeout(60000); if (index == -1) { handle = args[0]; host = WhoisClient.DEFAULT_HOST; } else { handle = args[0].substring(0, index); host = args[0].substring(index + 1); } try { address = InetAddress.getByName(host); System.out.println("[" + address.getHostName() + "]"); } catch (UnknownHostException e) { System.err.println("Error unknown host: " + e.getMessage()); System.exit(1); } try { whois.connect(address); System.out.print(whois.query(handle)); whois.disconnect(); } catch (IOException e) { System.err.println("Error I/O exception: " + e.getMessage()); System.exit(1); } }
From source file:at.tlphotography.jAbuseReport.Reporter.java
/** * Whois look up./* www . j a va 2 s . c o m*/ * * @param ip * the ip * @return the string */ private static String whoIsLookUp(String ip) { String[] serverList = { "whois.ripe.net", "whois.lacnic.net", "whois.registro.br" }; WhoisClient whois = new WhoisClient(); try { for (String server : serverList) { whois.connect(server); String whoisData1 = whois.query(ip); StringBuilder result = new StringBuilder(""); ; result.append(whoisData1); String mail = extractEMail(result.toString()); if (mail != null) return mail; } return "not found"; } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (whois.isConnected()) whois.disconnect(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; }
From source file:com.vish.phishDetect.Web_Utilities.java
public static int domainAge(String domainName) { StringBuilder whoisResult = new StringBuilder(""); WhoisClient crunchifyWhois = new WhoisClient(); try {//from www . ja va 2s . com // The WhoisClient class implements the client side of the Internet // Whois Protocol defined in RFC 954. To query a host you create a // WhoisClient instance, connect to the host, query the host, and // finally disconnect from the host. If the whois service you want // to query is on a non-standard port, connect to the host at that // port. crunchifyWhois.connect(WhoisClient.DEFAULT_HOST); String whoisData = crunchifyWhois.query("=" + domainName); whoisResult.append(whoisData); crunchifyWhois.disconnect(); } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String patternString1 = "No\\smatch\\sfor"; Pattern pattern = Pattern.compile(patternString1); Matcher matcher = pattern.matcher(whoisResult); if (!matcher.find()) { System.out.println(domainName + "\n" + whoisResult); } return 0;//whoisResult.toString(); }
From source file:com.thunder.network.WhoisCommand.java
@Override public void runCommand(final String host, final OnPartialResultListener listener) { new Thread(new Runnable() { @Override/* w ww .j a v a2s .co m*/ public void run() { StringBuilder result = new StringBuilder(""); WhoisClient whois = new WhoisClient(); try { whois.connect(WhoisClient.DEFAULT_HOST); String whoisData1 = whois.query("=" + host); result.append(whoisData1); listener.onPartialResult(result.toString()); listener.onFinish(); whois.disconnect(); } catch (IOException e) { e.printStackTrace(); listener.onError(e); } } }).start(); }
From source file:com.ecrimebureau.Web.Entity.WhoisS.java
private String queryWithWhoisServer(String domainName, String whoisServer) { String result = ""; WhoisClient whois = new WhoisClient(); try {//from w w w . j a va 2s . c om whois.connect(whoisServer); result = whois.query(domainName); whois.disconnect(); } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:com.ecrimebureau.Web.Entity.WhoisS.java
public String getWhois(String domainName) { StringBuilder result = new StringBuilder(""); WhoisClient whois = new WhoisClient(); try {//www. j a v a 2 s . co m whois.connect(WhoisClient.DEFAULT_HOST); // whois =google.com String whoisData1 = whois.query("=" + domainName); // append first result result.append(whoisData1); whois.disconnect(); // get the google.com whois server - whois.markmonitor.com String whoisServerUrl = getWhoisServer(whoisData1); if (!whoisServerUrl.equals("")) { // whois -h whois.markmonitor.com google.com String whoisData2 = queryWithWhoisServer(domainName, whoisServerUrl); // append 2nd result result.append(whoisData2); } } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result.toString(); }
From source file:org.apache.common.net.examples.unix.fwhois.java
public static final void main(String[] args) { int index;//from w w w. j a v a2 s . c o m String handle, host; InetAddress address = null; WhoisClient whois; if (args.length != 1) { System.err.println("usage: fwhois handle[@<server>]"); System.exit(1); } index = args[0].lastIndexOf("@"); whois = new WhoisClient(); // We want to timeout if a response takes longer than 60 seconds whois.setDefaultTimeout(60000); if (index == -1) { handle = args[0]; host = WhoisClient.DEFAULT_HOST; } else { handle = args[0].substring(0, index); host = args[0].substring(index + 1); } try { address = InetAddress.getByName(host); System.out.println("[" + address.getHostName() + "]"); } catch (UnknownHostException e) { System.err.println("Error unknown host: " + e.getMessage()); System.exit(1); } try { whois.connect(address); System.out.print(whois.query(handle)); whois.disconnect(); } catch (IOException e) { System.err.println("Error I/O exception: " + e.getMessage()); System.exit(1); } }
From source file:org.apache.commons.net.examples.unix.fwhois.java
public static void main(String[] args) { int index;//from ww w . ja v a 2 s.c om String handle, host; InetAddress address = null; WhoisClient whois; if (args.length != 1) { System.err.println("usage: fwhois handle[@<server>]"); System.exit(1); } index = args[0].lastIndexOf('@'); whois = new WhoisClient(); // We want to timeout if a response takes longer than 60 seconds whois.setDefaultTimeout(60000); if (index == -1) { handle = args[0]; host = WhoisClient.DEFAULT_HOST; } else { handle = args[0].substring(0, index); host = args[0].substring(index + 1); } try { address = InetAddress.getByName(host); System.out.println("[" + address.getHostName() + "]"); } catch (UnknownHostException e) { System.err.println("Error unknown host: " + e.getMessage()); System.exit(1); } try { whois.connect(address); System.out.print(whois.query(handle)); whois.disconnect(); } catch (IOException e) { System.err.println("Error I/O exception: " + e.getMessage()); System.exit(1); } }
From source file:org.apache.nifi.processors.enrich.TestQueryWhois.java
@Before public void setupTest() throws Exception { // This is what is sent by Mockito String header = "AS | IP | BGP Prefix | CC | Registry | Allocated | Info | AS Name\n"; String responseBodyLine1 = "999 | 123.123.123.123 | 123.123.123.123/32 | AU | apnic | 2014-01-01 | 2016-08-14 01:32:01 GMT | Apache NiFi\n"; String responseBodyLine2 = "333 | 124.124.124.124 | 124.124.124.124/32 | AU | apnic | 2014-01-01 | 2016-08-14 01:32:01 GMT | Apache NiFi\n"; WhoisClient whoisClient = PowerMockito.mock(WhoisClient.class); Mockito.when(whoisClient.query(Mockito.anyString())) .thenReturn(header + responseBodyLine1 + responseBodyLine2); this.queryWhois = new QueryWhois() { @Override//www . j a v a 2s . co m protected WhoisClient createClient() { return whoisClient; } }; this.queryWhoisTestRunner = TestRunners.newTestRunner(queryWhois); }