java通过地址获取主机名

关键代码:

try {

String str=Chat.getJt().getText().toString();//获取输入内容
String[] ipstr=str.split("[.]");
byte[] by=new byte[4];
for(int i=0;i<4;i++){
int m=Integer.parseInt(ipstr[i]);
byte b=(byte)(m&0xff);
by[i]=b;
}
InetAddress inet=InetAddress.getByAddress(by);
String pc=inet.getHostName();

} catch (UnknownHostException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}

原文地址:https://www.cnblogs.com/mafeng/p/4445459.html