连接过来的设备的信息存放

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012259618/article/details/52195719

1、连接过来的设备的信息存放在/data/misc/dhcp/dnsmasq.leases中

 

2、它的格式是:

 

/系统id,不需取值/client mac地址/client ip地址/ client device name/加权后mac地址,也不需取值

 

<spanstyle="font-size:14px;">1357041758 88:00:12:34:56:78192.168.43.133 android-184cc6c105d7a3b 01:88:00:12:34:56:78</span>

2、参考WifiServie.java的getClientIp()方法,可以自定义这个方法取得device name,具体如下:

 

<spanstyle="font-size:14px;">public String getClientDeviceName(StringdeviceAddress) {//传mac地址进来

enforceAccessPermission();

if(TextUtils.isEmpty(deviceAddress)) {

return null;

}

//读取对应的文件信息

for (String s :readClientList("/data/misc/dhcp/dnsmasq.leases")) {

if(s.indexOf(deviceAddress) != -1) {

String[] fields =s.split(" ");

//校验数据是否破损

if (fields.length> 4) {

//返回第4个栏位

return fields[3];

}

}

}

return null;

}</span>

 

3 在文件中的位置

Tethering.java(\\192.168.113.219\android\external2\android\lixy\1118-am809-sdk\809_apsdk_n\frameworks\base\services\core\java\com\android\server\connectivity)

private staticfinal String dhcpLocation = "/data/misc/dhcp/dnsmasq.leases";

readDeviceInfoFromDnsmasq()方法里面读出了文件里面的IP和物理地址

private booleanreadDeviceInfoFromDnsmasq(WifiDevice device) {

        boolean result = false;

        FileInputStream fstream = null;

        String line;

        try {

            fstream = newFileInputStream(dhcpLocation);

            DataInputStream in = newDataInputStream(fstream);

            BufferedReader br = new BufferedReader(newInputStreamReader(in));

            while ((null != (line = br.readLine()))&& (line.length() != 0)) {

                String[] fields =line.split(" ");

                // 949295 00:0a:f5:6a:bf:70192.168.43.32 android-93de88df9ec61bac *

                if (fields.length > 3) {

                    String addr = fields[1];

                    String name = fields[3];

                     System.out.println("LT-----addr="+addr+"name="+name);

                    if(addr.equals(device.deviceAddress)) {

                        device.deviceName =name;

                        result = true;

                        break;

                    }

                }

            }

        } catch (IOException ex) {

            Log.e(TAG,"readDeviceNameFromDnsmasq: " + ex);

        } finally {

            if (fstream != null) {

                try {

                    fstream.close();

                } catch (IOException ex) {}

            }

        }

        return result;

    }

猜你喜欢

转载自blog.csdn.net/u012259618/article/details/52195719