解决方案 »

  1.   

    android 执行linux命令 试试看 目测不需要root权限
      

  2.   

    EthernetDevInfo mEthInfo = mEthManager.getSavedEthConfig();
    Log.i(TAG, "mEthInfo == null :  " + (mEthInfo == null));
    if (mEthInfo != null) {
    String ipAddress = mEthInfo.getIpAddress();
    String netMask = mEthInfo.getNetMask();
    String dns = mEthInfo.getDnsAddr();
    String gateWay = mEthInfo.getRouteAddr();
      

  3.   


    额,linux命令的话,应该可以看到的,可是要怎么显示在android应用的界面上啊?求指点
      

  4.   

    EthernetDevInfo 这个class  import android.net.ethernet.EthernetDevInfo;会提示找不到啊,我在api里面也没有找到呢,难道真的像别人说的EthernetDevInfo 在framework层?这样的话,我怎么使用呢?傻眼了、、、、
      

  5.   

    把已经得到的信息的方法附上,都是从别人那里整理的,验证过木有问题。
    下面附上获取mac地址,以太网下获取IP的方法以及wifi下获取网络信息的方法。
    获取Mac地址:
    public static String getMacAddress(){
                try {
                    return loadFileAsString("/sys/class/net/eth0/address")
                        .toUpperCase().substring(0, 17);
                } catch (Exception e) {
                    e.printStackTrace();
                    return null;
                }
            }以太网下获取IP:
    public static String getLocalIpAddress() {
                    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()) {
                                                    return inetAddress.getHostAddress().toString();
                                            }
                                    }
                            }
                    } catch (SocketException ex) {
                            Log.e("WifiPreference IpAddress", ex.toString());
                    }
                    return null;
            }wifi下获取相关网络信息:wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    d = wm.getDhcpInfo();//将地址码转换成字符串类型
            public String FormatString(int value){
                String strValue="";
                byte[] ary =intToByteArray(value);
                for(int i=ary.length-1;i>=0;i--){
                        strValue+=(ary & 0xFF);
                        if(i>0){
                                strValue+=".";
                        }
                }
                return strValue;
        }        public  byte[] intToByteArray(int value){
            byte[] b = new byte[4];
             for (int i = 0; i < 4; i++){
                    int offset = (b.length - 1 - i) * 8;
                     b = (byte) ((value >>> offset) & 0xFF);
              }
              return b;
        }IP:FormatString(d.ipAddress).toString();
    默认网关:FormatString(d.gateway).toString();
    子网掩码:FormatString(d.netmask).toString();
      

  6.   

    不是来抬杠的,貌似你这个方法public static String getMacAddress(){并不能在所有的手机都 适用。我拿自己的手机测试了一下,并没有找到eth0这个节点。
    我的地址是/sys/class/net/wlan0/address
      

  7.   

    额、额、我的测试是在公司生产的平板上,不是在手机上测的,sorry,忘了说明了!
      

  8.   

    为什么我的获取 机顶盒 以太网的  ip地址,掩码,网关,DNS全为空啊!???????求解!!
      

  9.   

    public String getLocalHostIp() {
    String ipaddress = ""; try {
    Enumeration<NetworkInterface> en = NetworkInterface
    .getNetworkInterfaces();
    // Traverse the network interface
    while (en.hasMoreElements()) {
    NetworkInterface nif = en.nextElement();// Each network
    // interface binding,all
    // IP
    Enumeration<InetAddress> inet = nif.getInetAddresses();
    // Traverse each all the IP interface binding
    while (inet.hasMoreElements()) {
    InetAddress ip = inet.nextElement();
    if (!ip.isLoopbackAddress()
    && InetAddressUtils.isIPv4Address(ip
    .getHostAddress())) {
    Log.e("--------------------IP", ip.getHostAddress());
    return ipaddress = ip.getHostAddress();
    }
    }
    }
    } catch (SocketException e) {
    Log.e("---------------feige", "获取本地IP失败");
    e.printStackTrace();
    } return ipaddress;
    }