Android Open Source - TrafoControl Scan Devices Task






From Project

Back to project page TrafoControl.

License

The source code is released under:

MIT License

If you think the Android project TrafoControl listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bernhardeiling.trafocontrol.network;
//w  w  w  .  j a v  a  2  s . c  om
import android.os.AsyncTask;
import android.util.Log;

import com.bernhardeiling.trafocontrol.interfaces.ScanDevicesInterface;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;

/**
 * Created by Bernhard on 28.08.14.
 */
public class ScanDevicesTask extends AsyncTask<Void, Void, ArrayList<String>> {

    final static String TAG = "ScanDevices";
    public ScanDevicesInterface delegate;

    public ScanDevicesTask(ScanDevicesInterface delegate) {
        this.delegate = delegate;
    }

    @Override
    protected ArrayList<String> doInBackground(Void... urls) {

        BufferedReader reader = null;
        ArrayList<String> ipList = new ArrayList<String>();
        int timeout = 500;

        try {
            reader = new BufferedReader(new FileReader("/proc/net/arp"));
            String line;
            while ((line = reader.readLine()) != null) {

                String[] splitted = line.split(" +");
                if (splitted != null && splitted.length >= 4) {
                    String mac = splitted[3];
                    if (mac.matches("..:..:..:..:..:..")) {
                        if (InetAddress.getByName(splitted[0]).isReachable(timeout)) ipList.add(splitted[0]);
                    }
                }
            }
        } catch (FileNotFoundException e) {
            Log.e(TAG, e.getMessage());
        } catch (IOException e) {
            Log.e(TAG, e.getMessage());
        } finally {
            try {
                if (reader != null) reader.close();
            } catch (IOException e) {
                Log.e(TAG, e.getMessage());
            }
        }
        return ipList;
    }

    @Override
    protected void onPostExecute(ArrayList<String> ipList) {
        delegate.onFinishScanningConnectedDevices(ipList);
    }
}




Java Source Code List

com.bernhardeiling.trafocontrol.ApplicationTest.java
com.bernhardeiling.trafocontrol.MainActivity.java
com.bernhardeiling.trafocontrol.animation.AnimationContainer.java
com.bernhardeiling.trafocontrol.animation.AnimationController.java
com.bernhardeiling.trafocontrol.animation.Animation.java
com.bernhardeiling.trafocontrol.animation.LoadAnimationThread.java
com.bernhardeiling.trafocontrol.animation.SyncAnimationThread.java
com.bernhardeiling.trafocontrol.interfaces.ScanDevicesInterface.java
com.bernhardeiling.trafocontrol.network.AccessPoint.java
com.bernhardeiling.trafocontrol.network.ScanDevicesTask.java