调用方式:
getIpAddrForInterfaces("eth0");
getIpAddrMaskForInterfaces("eth0");
getGateWay();
etDns(context);
/**
* ip
*/
public static String getIpAddrForInterfaces(String interfaceName) {
try {
Enumeration<NetworkInterface> enNetworkInterface = NetworkInterface.getNetworkInterfaces(); //获取本机所有的网络接口
while (enNetworkInterface.hasMoreElements()) { //判断 Enumeration 对象中是否还有数据
NetworkInterface networkInterface = enNetworkInterface.nextElement(); //获取 Enumeration 对象中的下一个数据
if (!networkInterface.isUp()) { // 判断网口是否在使用
continue;
}
if (!interfaceName.equals(networkInterface.getDisplayName())) { // 网口名称是否和需要的相同
本文介绍如何在Android 9.0系统中获取设备的IP地址、子网掩码、网关和DNS设置。通过特定的API调用,开发者可以获取到这些关键的网络配置参数。
订阅专栏 解锁全文
2108





