android - 在 Android Studio 中 Ping 本地 IP
问题描述
我正在尝试开发一种方法来检查 IP 方向是否可达,我发现了一个类似的问题,但它不起作用 Android Application Ping IP 号码
private void existePingServidor(){
InetAddress in;
try{
in = InetAddress.getByName("90.0.0.122");
if (in.isReachable(5000)){
pingServidor = true;
Log.v("true","He pasado por aquí");
}
else
pingServidor = false;
Log.v("false", "No he podido alcanzar la ip");
}
catch(Exception e){
e.printStackTrace();
}
}
问题似乎是 InetAddress.getByName("90.0.0.122"); 返回空
¿你能解释一下在android studio中ping一个IP的正确方法是什么吗?
解决方案
尝试 getByAddress 代替:
byte [] ip = {90, 0, 0, 122};
addr = InetAddress.getByAddress(ip);
addr.isReachable(5000);
推荐阅读
- html - 如何使用 FabricJS 创建形状不规则的 HTML 画布?
- jquery - jQuery; 对根据动态创建的变量的值创建的类应用样式
- go - golang,在 2 个模型之间创建关系并使用 gorm 通过 Preload 检索它们
- python - 在 Python 中组合从 .split() 生成的列表
- python-3.x - Easyviz 和 scitools.std 仍然适用于 python3?除了从一系列图像制作电影之外,还有其他方法吗?
- java - 抛硬币方法建议
- python - 使用while循环时如何在python中排除空行和小于零的数字
- jquery - 元素不会隐藏 - Jquery
- c++ - 使用c ++使用opencv更改特定区域内的颜色
- python - 使用库 pyftpdlib 从 python 中的 FTP 服务器断开连接