Connect server to local network by hostname

Asked

Viewed 143 times

1

I am trying to connect to a local network server using the hostname (can not use IP because the client network does not allow to put fixed ip and the equipment does not have IP reservation for MAC).

So, I’m trying to do this from an Android application, until the moment I was able to search the IP from the hostname but as there is more than one network card on the machine, is only returning me one of the Ips.

The code that is returning me an IP is as follows: (in asyncTask)

ArrayList <String> lista = new ArrayList<String>();

try
{
    InetAddress ipaddress = InetAddress.getByName(hostname);
    lista.add(ipaddress.getHostAddress());
}
catch (UnknownHostException e)
{
    lista.add("Ip não encontrado para o hostname: "+ hostname);
}

return  lista;

1 answer

3


I found in the stack in English the following code.

try {
Log.d("ReverseDNS", "Reverse DNS for 8.8.8.8 is: " + InetAddress.getByName("8.8.8.8").getHostName());
} catch (UnknownHostException e) {
 Log.e("ReverseDNS", "Oh no, 8.8.8.8 has no reverse DNS record!");
}

It uses a Reverse Lookup DNS, this operation may take a while, so run on an asynchronous task.

Link of the question in English.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.