如何在android上以编程方式更改ipv4地址?

时间:2014-12-10 12:30:04

标签: android networking static ip

我可以通过此代码阅读ipv4

public String getLocalIpAddress() {
         String ipaddress = null;
         try {

                for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                    NetworkInterface intf = en.nextElement();
                    for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                        InetAddress inetAddress = enumIpAddr.nextElement();
                        //if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && inetAddress.isSiteLocalAddress() ) {
                        if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress()) ) {
                             ipaddress = inetAddress.getHostAddress();

                        }
                    }
                }
            } catch (SocketException ex) {
            //    Log.d(TAG, ex.toString());
            }

        return ipaddress;
    }

但我无法改变它。有没有办法通过代码更改静态IP?我只能在设置配置以太网设备菜单上更改它

0 个答案:

没有答案