Connect server to local network by hostname

1

I am trying to connect to a local network server using hostname (you can not use IP because the client network does not allow fixed ip and the device does not have IP backup per MAC).

So, I'm trying to do this from an Android application, so far I've been able to get the IP from the hostname but since there is more than one network card on the machine, 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;
    
asked by anonymous 10.06.2016 / 14:37

1 answer

3

I found the following code in the English stack.

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 DNS Reverse Lookup, this operation may take a while, so run an asynchronous task.

Link of the question in English

    
10.06.2016 / 15:24