LAN 네트워크에서 연결된 IP 주소와 호스트 이름을 가진 작은 안드로이드 앱을 만들고 싶습니다. 연결된 LAN 네트워크에서 IP 주소를 얻으려면 훌륭하게 작동하는 코드가 있지만 IP 주소의 호스트 이름을 얻는 방법을 모르겠습니다. 코드를 변경해야하는 곳. 나쁜 영어를 유감스럽게 생각합니다. 여기 안드로이드에서 IP 주소의 호스트 이름을 얻는 방법?
는 LAN 네트워크에
String connections = "";
InetAddress host;
try
{
host = InetAddress.getByName("192.168.1.1");
byte[] ip = host.getAddress();
for(int i = 1; i <= 254; i++)
{
ip[3] = (byte) i;
InetAddress address = InetAddress.getByAddress(ip);
if(address.isReachable(100))
{
System.out.println(address + " machine is turned on and can be pinged "+address.getCanonicalHostName());
connections+= address+"\n";
}
else if(!address.getHostAddress().equals(address.getHostName()))
{
System.out.println(address + " machine is known in a DNS lookup");
System.out.println(address.getHostAddress()+"host Name:"+ address.getHostName());
}
}
tv.setText(connections);
}
catch(UnknownHostException e1)
{
e1.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
어떤 항목 호스트가 이것 –
봐 파일에 당신이 할 그것은 당신의 문제를 해결할 것입니다 : http://stackoverflow.com/questions/21521844/how-to-resolve-network-host-names-from-ip-address –
Shreyas,이 InetAddress.getByName ("192.168. 1.2 "). getHostName() 링크를 연 후 여전히 동일한 IP 192.168.1.2 –