get non connected devices, when my device are in tethering mode

7

i am activating tethering mode with this code:

private void setWifiTetheringEnabled(boolean enable) {
    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);

    Method[] methods = wifiManager.getClass().getDeclaredMethods(); 
    for (Method method : methods) {
        Log.e("teste", method.getName());
        if (method.getName().equals("setWifiApEnabled")) {
            try {
                method.invoke(wifiManager, null, enable);
            } catch (Exception ex) {
            }
            break;
        }
    }
}

and i am getting devices connected using this code (and reading the information)

   br = new BufferedReader(new FileReader("/proc/net/arp"));

but in this file (/proc/net/arp) has only connected devices, i want get some info (Mac address) about a device that just scanned my phone in tethering mode.

executing ntcfg my return:

 04-10 10:32:27.908: E/test(18908): dummy0   DOWN                                   0.0.0.0/0   0x00000082 xx:xx:b6:69:37:4e
04-10 10:32:27.908: E/test(18908): wlan0    UP                                192.168.43.1/24  0x00001043 xx:xx:11:f9:a9:45
04-10 10:32:27.908: E/test(18908): rmnet_usb0 UP                              100.107.189.66/30  0x00000041 00:00:00:00:00:00
04-10 10:32:27.908: E/test(18908): rmnet_usb1 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
04-10 10:32:27.908: E/test(18908): rmnet_usb2 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
04-10 10:32:27.908: E/test(18908): rmnet_usb3 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
04-10 10:32:27.908: E/test(18908): lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:00:00:00
04-10 10:32:27.908: E/test(18908): sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
04-10 10:32:27.908: E/test(18908): rmnet_smux0 DOWN                                   0.0.0.0/0   0x00001002 xx:6f:06:64:e2:61
04-10 10:32:27.908: E/test(18908): rmnet0   DOWN                                   0.0.0.0/0   0x00001002 xx:xx:a4:fe:a4:e5
04-10 10:32:27.908: E/test(18908): rmnet1   DOWN                                   0.0.0.0/0   0x00001002 xx:x:68:34:70:29
04-10 10:32:27.908: E/test(18908): rmnet2   DOWN                                   0.0.0.0/0   0x00001002 xx:xx:ac:a5:b3:a1
04-10 10:32:27.908: E/test(18908): rmnet3   DOWN                                   0.0.0.0/0   0x00001002 xx:xx:1b:af:02:fe
04-10 10:32:27.908: E/test(18908): rmnet4   DOWN                                   0.0.0.0/0   0x00001002 xx:xx:32:79:22:e7
04-10 10:32:27.908: E/test(18908): rmnet5   DOWN                                   0.0.0.0/0   0x00001002 xx:xx:9b:4c:93:c5
04-10 10:32:27.908: E/test(18908): rmnet6   DOWN                                   0.0.0.0/0   0x00001002 xx:xx:1a:1e:86:e8
04-10 10:32:27.908: E/test(18908): rmnet7   DOWN                                   0.0.0.0/0   0x00001002 xx:xx:46:f0:c5:48
04-10 10:32:27.908: E/test(18908): rev_rmnet2 DOWN                                   0.0.0.0/0   0x00001002 xx:xx:98:22:6f:fb
04-10 10:32:27.908: E/test(18908): rev_rmnet3 DOWN                                   0.0.0.0/0   0x00001002 xx:xx:8d:bf:3e:50
04-10 10:32:27.908: E/test(18908): rev_rmnet4 DOWN                                   0.0.0.0/0   0x00001002 xx:xx:f4:c0:81:ae
04-10 10:32:27.908: E/test(18908): rev_rmnet5 DOWN                                   0.0.0.0/0   0x00001002 xx:xx:29:94:d5:e5
04-10 10:32:27.908: E/test(18908): rev_rmnet6 DOWN                                   0.0.0.0/0   0x00001002 xx:xx:41:39:44:db
04-10 10:32:27.908: E/test(18908): rev_rmnet7 DOWN                                   0.0.0.0/0   0x00001002 xx:xx:4b:0b:13:18
04-10 10:32:27.908: E/test(18908): rev_rmnet8 DOWN                                   0.0.0.0/0   0x00001002 xx:xx:64:4f:b4:f6
04-10 10:32:27.908: E/test(18908): rev_rmnet0 DOWN                                   0.0.0.0/0   0x00001002 xx:xx:f4:d2:ae:66
04-10 10:32:27.908: E/test(18908): rev_rmnet1 DOWN                                   0.0.0.0/0   0x00001002 xx:xx:8d:f0:64:2a
android
android-wifi
tethering
asked on Stack Overflow Apr 1, 2015 by rcorbellini • edited Apr 10, 2015 by rcorbellini

1 Answer

-1

Call exec("netcfg");


/**
 * Execute a command in a shell
 * 
 * @param command
 *            command to execute
 * @return the return of the command
 */
public String exec(String command) {
    String retour = "";
    try {
        Runtime runtime = Runtime.getRuntime();

        Process p = runtime.exec(command);

        java.io.BufferedReader standardIn = new java.io.BufferedReader(
                new java.io.InputStreamReader(p.getInputStream()));
        java.io.BufferedReader errorIn = new java.io.BufferedReader(
                new java.io.InputStreamReader(p.getErrorStream()));
        String line = "";
        while ((line = standardIn.readLine()) != null) {
            retour += line + "\n";
        }
        while ((line = errorIn.readLine()) != null) {
            retour += line + "\n";
        }
    } catch (java.io.IOException e) {
        e.printStackTrace();
    }

    return retour;
}

It will execute "netcfg" command in the shell & produces output like the following

lo       UP           127.0.0.1/8   0x00000049  00:00:00:00:00:00

sit0     DOWN         0.0.0.0/0     0x00000080  00:00:00:00:00:00

eth0     UP           0.0.0.0/0     0x00001003  78:c5:e5:a2:b2:d0

wlan0    DOWN         0.0.0.0/0     0x00001002  64:70:02:20:79:31

Including connected network interfaces , status , IP obtained & MAC address .

The last field is for MAC address. You have to parse the MAC address from this single String.

answered on Stack Overflow Apr 10, 2015 by Don Chakkappan • edited Apr 10, 2015 by Don Chakkappan

User contributions licensed under CC BY-SA 3.0