Android Open Source - AndroidLookup Lookup Whois Task






From Project

Back to project page AndroidLookup.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidLookup listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * //w  w  w . j a  v  a  2  s. co m
 */
package com.jburto2.androidlookup;

import java.io.IOException;
import java.net.SocketException;

import org.apache.commons.net.whois.WhoisClient;

/**
 * @author James Burton
 * 
 * @class LookupWhoisTask 
 * @brief This class is an LookupTask that looks up a hostname given an IP address and an IP address if given a hostname.
 * Adapted from http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception
 * 
 */
public class LookupWhoisTask extends LookupTask
{

  
  /**
   * @fn protected String doInBackground(String... urls)
   * 
   * @brief This function uses org.apache.commons.net.whois.WhoisClient to get the whois information for a site.
   * 
   * Adapted from from http://www.mkyong.com/java/java-whois-example/
   * 
   * @param urls Array of strings that are arguments to the function. url[0] is the address to lookup.
   * @return String that represents either the IP address or the hostname if call succeeded.
   * @return null If the call failed. 
   * @exception Exception generated from InetAddress call is stored in the public instance variable exception.
   * 
   */
  
    protected String doInBackground(String... urls) 
    {
      String url = urls[0];
      
      
      
      StringBuilder result = new StringBuilder("");
       
    WhoisClient whois = new WhoisClient();
    try 
    {
 
      //default is internic.net
      whois.connect(WhoisClient.DEFAULT_HOST);
      String whoisData1 = whois.query("=" + url);
      result.append(whoisData1);
      whois.disconnect();
 
    } 
    catch (SocketException e) 
    {
      e.printStackTrace();
    } 
    catch (IOException e) 
    {
      e.printStackTrace();
    }
 
    return result.toString();
    }
    
    /**
     * @fn protected void onPostExecute(String str)
     * 
     * @brief Method to be done after the task has executed.
     * @param str Some string 
     */

    protected void onPostExecute(String str) 
    {
        // TODO: check this.exception 
        // TODO: do something with the feed
    }

}




Java Source Code List

com.jburto2.androidlookup.DisplayInfoActivity.java
com.jburto2.androidlookup.DisplayLookupActivity.java
com.jburto2.androidlookup.DisplayWhoisActivity.java
com.jburto2.androidlookup.LookupAddressTask.java
com.jburto2.androidlookup.LookupCNAMETask.java
com.jburto2.androidlookup.LookupPingTask.java
com.jburto2.androidlookup.LookupTask.java
com.jburto2.androidlookup.LookupWhoisTask.java
com.jburto2.androidlookup.MainActivity.java
com.jburto2.androidlookup.TableLayoutUtils.java