本文为转载,原博地址忘记了,参考的代码然后进行调试成功,原博主看到见谅。
主要功能是,自身是无线热点,获取连接自身的设备IP列表
GetConnectIP.java
package wifi.localinfo; import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; public class GetConnectIP { static StringBuilder resultList; static ArrayList<String> connectedIP; public static ArrayList<String> getAllIp() { try { connectedIP = getConnectIp(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } resultList = new StringBuilder(); for (String ip : connectedIP) { resultList.append(ip); try { connectedIP = getConnectIp(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return connectedIP; } public static String getOneIp() { return getAllIp().get(1); } private static ArrayList<String> getConnectIp() throws Exception { ArrayList<String> connectIpList = new ArrayList<String>(); BufferedReader 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) { String ip = splitted[0]; connectIpList.add(ip); } } return connectIpList; } }
具体调用
GetConnectIP.getOneIp();如有问题,欢迎指出。