hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Quintin Beukes" <quin...@last.za.net>
Subject Re: How to get HOST IP address ?
Date Mon, 30 Jun 2008 12:30:38 GMT
Hey,

Well, there are 2 techniques, first is to simply use the
InetAddress.getByName() method which will query the system's
configured DNS server (recommended in general). Second technique is
used when you wish to query a specific DNS server (not the one used by
the system).

The first technique is done like this:
    InetAddress ip = InetAddress.getByName("dev.junkmail.co.za");
    System.out.println("IP: " + ip.getHostAddress());

Over here, the "InetAddress ip" object has a few methods for
retrieving the IP address. Have a look at the JavaDoc to learn more.

The second technique is done like this:

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.dns.DnsContextFactory");
    env.put(Context.PROVIDER_URL, "dns://10.0.0.1/");
    DirContext ictx = new InitialDirContext(env);
    Attributes attrs1 = ictx.getAttributes("www.junkmail.co.za", new
String[] {"A"});

    // get first IP
    System.out.println("First IP: " + attrs1.get("A").get().toString());

    // get all IP addresses
    NamingEnumeration nameEnum = attrs1.get("A").getAll();
    while (nameEnum.hasMore())
    {
      Object aRecord = nameEnum.next();
      System.out.println("A record: " + aRecord.toString());
    }

Over here you will see that you can either query for only the first
record/IP, or enumerate through all of them. You will have to handle
some exceptions with this technique (like NoSuchElementException if an
IP/A record couldn't be found, and NamingException for misc errors
like DNS connection failures).

hope this helps,
Quintin

On 6/30/08, Laxmilal Menaria <menarialaxmilal@gmail.com> wrote:
> Hello,
>
>  I have created a sample to check the my webpage status, now want to
>  get  IP address of "http://laxmilal.com", so is there are any method
>  to get HOST IP ?
>
>   method = new GetMethod("http://laxmilal.com");
>   int statusCode = httpClient.executeMethod(secureHostConfig, method);
>
>
>  Please let me know.
>
>  Thanks
>  Laxmilal
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>  For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 
Quintin Beukes

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message