Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ArrayList<InetAddress> getConnectedDevices(String YourPhoneIPAddress) {
- ArrayList<InetAddress> ret = new ArrayList<InetAddress>();
- LoopCurrentIP = 0;
- String IPAddress = "";
- String[] myIPArray = YourPhoneIPAddress.split("\\.");
- InetAddress currentPingAddr;
- for (int i = 0; i <= 255; i++) {
- try {
- // build the next IP address
- currentPingAddr = InetAddress.getByName(myIPArray[0] + "." +
- myIPArray[1] + "." +
- myIPArray[2] + "." +
- Integer.toString(LoopCurrentIP));
- ad = currentPingAddr.toString(); /////////////////
- Log.d("MyApp",ad); //////////////
- // 50ms Timeout for the "ping"
- if (currentPingAddr.isReachable(50)) {
- ret.add(currentPingAddr);
- ad = currentPingAddr.toString(); /////////////////
- Log.d("MyApp",ad); //////////////
- }
- } catch (UnknownHostException ex) {
- } catch (IOException ex) {
- }
- LoopCurrentIP++;
- }
- return ret;
- }
- public static String getMacFromArpCache(String ip) {
- if (ip == null)
- return null;
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader("/proc/net/arp"));
- String line;
- while ((line = br.readLine()) != null) {
- String[] splitted = line.split(" +");
- if (splitted != null && splitted.length >= 4 && ip.equals(splitted[0])) {
- // Basic sanity check
- String mac = splitted[3];
- if (mac.matches("..:..:..:..:..:..")) {
- return mac;
- } else {
- return null;
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement