app实现dns解析
来源:互联网 发布:免费下载cad2008软件 编辑:程序博客网 时间:2024/05/18 15:52
apk上层做了个类似dns解析的小功能,主要分为两步:
- 1.判断当前网络是否通畅
涉及下面两个类
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
boolean isNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null && info.isConnected()) { if (info.getState() == NetworkInfo.State.CONNECTED) { return true; } } } return false; }
- 2.解析域名
涉及下面类
import java.net.InetAddress;
InetAddress address = InetAddress.getByName("www.baidu.com"); //下面的hostaddress 既是类似180.97.33.108这样的点分形式 String HostAddress = address.getHostAddress();
下面是InetAddress.getByName的api文档,使用时需要注意输入和捕获异常,此外android也规定网络连接等耗时的操作需要另起一个线程,不能在主线程运行。
public static InetAddress getByName (String host)Added in API level 1Returns the address of a host according to the given host string name host. The host string may be either a machine name or a dotted string IP address. If the latter, the hostName field is determined upon demand. host can be null which means that an address of the loopback interface is returned.Parametershost the hostName to be resolved to an address or null.Returns the InetAddress instance representing the host.ThrowsUnknownHostException if the address lookup fails.
0 0
- app实现dns解析
- C#实现DNS解析服务
- w5100实现dns解析功能
- 《Python实现DNS解析查询》
- Radvision H248 DNS解析机制实现
- Chrome是如何实现DNS的解析
- DNS以及DNS解析
- DNS 解析
- DNS解析
- DNS解析
- Dns解析
- dns解析
- dns解析
- DNS解析
- DNS解析
- DNS解析
- DNS解析
- DNS解析
- 003.Comment 注释
- Agile PLM --- JAX-WS 2.2 API is required, but an older version was found in the JDK
- 软件架构设计模式
- Codeforces 591 B Rebranding【Codeforces Round #327 (Div. 2)】
- 002.HelloWorld 单视图工程
- app实现dns解析
- 8_20 文件解释器
- 二值连通区域检测
- spring/hibernate 优化
- C++函数返回二维数组
- 求最长回文子串的Manacher算法,time O(n)
- 神经网络数据结构
- 001.HelloWorld 命令行工程
- Add Digits