How can I get an IP address of a server?
I have built a client-server pair. The client makes DNS requests from the server (which is on local host), and if the ip address isn't in the cache the server is supposed to send the request out to the world, get back the answer, add it to the cache and reply to the client...
The code i'm trying is:
class DNSProtocol
{
String ans;
acache cache;
String theInput;
public DNSProtocol(acache thisCache)
{
cache = thisCache;
}
public String processInput(String theInput)
{
String theOutput =null;
System.out.println("In the protocol");
//check if ip is cached
ans = checkCache(theInput);
try
{
if (!ans.equalsIgnoreCase("IP Unknown"))
{
System.out.println("theOutput = "+ans);
theOutput = ans;
}
else
{
System.out.println("Not found in Cache..Checking ext");
theOutput = InetAddress.getByName(theInput).getHostAddress();
}
}
catch(UnknownHostException e)
{
ans = ("Unknown Host!!");
theOutput = ans;
}
return theOutput;
}
The search of the cache works, but when i try to resolve the address using:
InetAddress.getByName(theInput).getHostAddress();
I get Host Unknown (which is what i have set the reply to be if it can't resolve it).
I believe this is because it isn't sending the request out, but how do I do it?Pls help!!
Thanks in advance
Lee

