我想这个代码为了ping在局域网中的IP地址..结果返回是对不起。Ping一个IP地址
谢谢。如果你帮我
我想从我的设备ping打印机的ip。我可以这样做吗?
String ip_address="\\10.28.81.9";
boolean reachable=false;
TextView txt=(TextView) findViewById(R.id.info);
InetAddress address;
try {
address = InetAddress.getByName(ip_address);
reachable =address.isReachable(3000);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(reachable){
txt.setText("Got it");
}else{
txt.setText("Sorry");
}
我也很厌倦通过删除\\与IP地址,但它仍然没有工作。 – 2012-01-11 08:22:33
可能重复的[Java代码来ping IP地址](https://stackoverflow.com/questions/11506321/java-code-to-ping-an-ip-address) – 2017-09-18 08:04:52