get Server Ip From Arp Cache - Android java.net

Android examples for java.net:IP Address

Description

get Server Ip From Arp Cache

Demo Code

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Main{

    public static String getServerIpFromArpCache() {
        BufferedReader br = null;
        try {//from  ww  w. ja v a2 s .  c  om
            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