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
rcorbellini
  • 1,307
  • 1
  • 21
  • 42

1 Answers1

-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.

Don Chakkappan
  • 7,397
  • 5
  • 44
  • 59
  • can you explain a litle more the string returned? i think this can be my answer... the return have alot of information, which one I may consider a valid device scanned? – rcorbellini Apr 10 '15 at 12:58
  • i get alot of things... i dont have a root access, in your case can you consider you have 4 devices scanned and 2 of them are connnected? it ist? – rcorbellini Apr 10 '15 at 13:27
  • In ma none of them are connected.Could you please show the output? – Don Chakkappan Apr 10 '15 at 13:28
  • Currently wlan0 & rmnet_usb0 are connected .Because they are in UP state & they have some IP address. How many WIFI networks are available while scanning ? – Don Chakkappan Apr 10 '15 at 13:39
  • here have alot of networks in scanning i think its around 8-10 and have alot of devices i think its around 15... witch this code i wanna count (and if possible get mac address) of devices scanned me. – rcorbellini Apr 10 '15 at 14:01
  • its not workin, have one android connected on me with the end mac xx:xx:xx:xx:xx:4c and in netcfg its not appear – rcorbellini Apr 10 '15 at 16:08