Android应用程序Ping IP号
使用Android应用程序时,用户在editview Ex:(192.100.10.10)中输入网络IP号。在继续之前,我想看看网络IP是否存在。您的代码应该是这样的:Android应用程序Ping IP号,android,Android,使用Android应用程序时,用户在editview Ex:(192.100.10.10)中输入网络IP号。在继续之前,我想看看网络IP是否存在。您的代码应该是这样的: InetAddress in; //try to parse address try { in = InetAddress.getByName("192.100.10.10"); } catch (UnknownHostException e) { //incorrect IP } try { //wa
InetAddress in;
//try to parse address
try {
in = InetAddress.getByName("192.100.10.10");
} catch (UnknownHostException e) {
//incorrect IP
}
try {
//wait for response (500ms)
if (in.isReachable(5000)) {
//host reachable
} else {
//no host found/timeout
}
} catch (IOException e) {
// IOException
}
克丽斯特拉顿值得称赞是的,他们有一半有效的东西。但这两个问题本质上仍然是“我如何在android中ping?”。