get Server Ip From Arp Cache - Android Phone

Android examples for Phone:wifi

Description

get Server Ip From Arp Cache

Demo Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    public static String getServerIpFromArpCache() {
        BufferedReader br = null;
        try {/*from   w w w  . j  ava  2 s.com*/
            br = new BufferedReader(new FileReader("/proc/net/arp"));
            String line;
            if ((line = br.readLine()) != null) {
                line = br.readLine();
                String[] splitted = line.split(" +");
                // Basic sanity check
                String ip = splitted[0];
                return ip;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}

Related Tutorials