Need an InetAddress using a host
Im adding password authentication to some code but I seem to have run into a problem. All of the requestPasswordAuthentication methods within the Authenticator class take an InetAddress object as an arg. I can't figure out how to get an instance of an InetAddres object just using a host name. The only methods that return a new instance are the following. With the last not returning an InetAddress but an IP address for the given host name.
Code:
static InetAddress getByAddress(byte[] addr)
static InetAddress getByAddress(String host, byte[] addr)
static InetAddress getByName(String host)
I could use getByName(String host) to get the ip address then parse it into a byte array to use for getByAddress(byte[] addr) but that's really a pain.
Re: Need an InetAddress using a host
Wait a moment. How can it return an IP address if the return type is InetAddress?
Besides which, the InetAddress type is merely a wrapper around an IP address.
Re: Need an InetAddress using a host
I must have read the docs wrong. :blush: :lol: They say the following......
Quote:
Parameters:
host - the specified host, or null.
Returns:
an IP address for the given host name.
Re: Need an InetAddress using a host
Can't figure out why the code keeps throwing an java.net.UnknownHostException. :confused: I am prretty sure it's thrown at the line where the stream is opened from the URL. The URL is correct or the runtime would throw a java.net.MalformedURLException.
Code:
buff = new BufferedReader(new InputStreamReader(new URL(target).openStream()));
Re: Need an InetAddress using a host
Seems a UnknownHostException is thrown if no IP address for the host could be found, or if a scope_id was specified for a global IPv6 address. I guess the DNS canno't determine the ip address of msn.com and a few other sites I tried. :sick: