java android Q从hotspot/proc/net/arp读取ip:open失败:EACCES(权限被拒绝)

java android Q从hotspot/proc/net/arp读取ip:open失败:EACCES(权限被拒绝),java,android,Java,Android,我想读取仅在android上连接到我的热点的ip Q我有一个问题: 这是一个日志: java.io.FileNotFoundException: /proc/net/arp: open failed: EACCES (Permission denied) 以下是不起作用的: br = new BufferedReader(new FileReader("/proc/net/arp")); 我在舱单上加上: android:requestLegacyExternalStorage="true

我想读取仅在android上连接到我的热点的ip Q我有一个问题: 这是一个日志:

java.io.FileNotFoundException: /proc/net/arp: open failed: EACCES (Permission denied)
以下是不起作用的:

 br = new BufferedReader(new FileReader("/proc/net/arp"));
我在舱单上加上:

android:requestLegacyExternalStorage="true"
添加所有权限。我还添加:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (Settings.System.canWrite(ListOfTerminalsActivity.this)) {
        } else {
            Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
            intent.setData(Uri.parse("package:" + getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                startActivity(intent);
            } catch (ActivityNotFoundException ignored) {
            }
        }
    }

Android 10以后版本不允许访问“/proc/net/arp”。有关更多信息,请参阅Android 10及以后版本,不允许访问“/proc/net/arp”。有关更多信息,请参阅模式macPattern=Pattern.compile(“…:…”); BufferedReader br=null; 试一试{ if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.Q){ 进程ipProc=Runtime.getRuntime().exec(IP_CMD); ipProc.waitFor(); if(ipProc.exitValue()!=0){ 抛出新异常(“无法访问ARP条目”); } br=新的BufferedReader(新的InputStreamReader(ipProc.getInputStream(),“UTF-8”); 弦线; 而((line=br.readLine())!=null){ 字符串[]邻接线=line.split(\\s+); if(neighborLine.length
Pattern macPattern=Pattern.compile(“…:”);
BufferedReader br=null;
试一试{
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.Q){
进程ipProc=Runtime.getRuntime().exec(IP_CMD);
ipProc.waitFor();
if(ipProc.exitValue()!=0){
抛出新异常(“无法访问ARP条目”);
}
br=新的BufferedReader(新的InputStreamReader(ipProc.getInputStream(),“UTF-8”);
弦线;
而((line=br.readLine())!=null){
字符串[]邻接线=line.split(\\s+);

如果(neighborLine.length)你找到解决方案了吗?@Manzotin是的,我愿意分享吗?@Manzotin是的,我愿意分享吗?@Manzotin是的,我愿意分享吗?@Manzotin是的,我愿意分享第7行的IP_CMD值是多少?@Manzotin私有静态最终字符串IP_CMD=“IP neighbor”;第7行的IP_CMD值是多少?@Manzotin private static final String IP_CMD=“IP neighbor”;
 Pattern macPattern = Pattern.compile("..:..:..:..:..:..");

            BufferedReader br = null;
            try {

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                    Process ipProc = Runtime.getRuntime().exec(IP_CMD);
                    ipProc.waitFor();
                    if (ipProc.exitValue() != 0) {
                        throw new Exception("Unable to access ARP entries");
                    }

                    br = new BufferedReader(new InputStreamReader(ipProc.getInputStream(), "UTF-8"));
                    String line;
                    while ((line = br.readLine()) != null) {
                        String[] neighborLine = line.split("\\s+");
                        if (neighborLine.length <= 4) {
                            continue;
                        }
                        String ip = neighborLine[0];
                        final String hwAddr = neighborLine[4];

                        InetAddress addr = InetAddress.getByName(ip);
                        if (addr.isLinkLocalAddress() || addr.isLoopbackAddress()) {
                            continue;
                        }
                        String macAddress = neighborLine[4];
                        String state = neighborLine[neighborLine.length - 1];

                        if (!NEIGHBOR_FAILED.equals(state) && !NEIGHBOR_INCOMPLETE.equals(state)) {
                            boolean isReachable = false;
                            try {
                                isReachable = InetAddress.getByName(ip).isReachable(5000);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            if (isReachable) {
                                result.add(new WifiClient(ip, hwAddr));
                            }
                        }
                    }
                } else {
                    br = new BufferedReader(new FileReader("/proc/net/arp"));
                    String line;
                    while ((line = br.readLine()) != null) {
                        String[] parts = line.split(" +");
                        if (parts.length < 6) {
                            continue;
                        }
                        final String ipAddr = parts[0];
                        final String hwAddr = parts[3];
                        if (!ipAddr.equalsIgnoreCase("IP")) {
                            boolean isReachable = false;
                            try {
                                isReachable = InetAddress.getByName(ipAddr).isReachable(5000);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            if (isReachable) {
                                result.add(new WifiClient(ipAddr, hwAddr));
                            }
                        }

                    }
                }
            } catch (Exception e) {
            } finally {
                try {
                    if (br != null) {
                        br.close();
                    }
                } catch (IOException e) {
                }
            }