获取连接到本手机热点的什么的mac及ip

 你在需要的地方调用这个工具类就可以了.

/**
 * 从手机本地文件提取Ip地址与mac
 * return List<Mac_Ip> ipmac = new ArrayList<>();
 */
public class GetIp {

    private Mac_Ip mac_ip = null;
    private List<Mac_Ip> macIps = new ArrayList<>();
    private List<Mac_Ip> ipmac = new ArrayList<>();
    private BufferedReader br = null;
    private String line;


    public List<Mac_Ip> getIp(){
        try {
            br = new BufferedReader(new FileReader("/proc/net/arp"));
            macIps.clear();
            ipmac.clear();
            line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] splitted = line.split(" +");
                if (splitted != null && splitted.length >= 4) {
                    String ip = splitted[0].trim();
                    String mac = splitted[3].trim();
                    mac_ip = new Mac_Ip(ip,mac);
                    macIps.add(mac_ip);
                }
            }
            for (int i=0;i<macIps.size();i++){
                String sixmac = macIps.get(i).getMac().toString().trim();
                String[] splitted = sixmac.split(":");
                System.out.print(splitted);
                String eight = splitted[0].trim()+splitted[1].trim()+splitted[2].trim();
                String xc = "888888";
                if (eight.toString().trim().equals(xc)){
                    String ip = macIps.get(i).getIp().toString().trim();
                    String mac = macIps.get(i).getMac().toString().trim();
                    if (ipmac.size()==0){
                        mac_ip.setIp(ip);
                        mac_ip.setMac(mac);
                        ipmac.add(mac_ip);
                    }else {
                        for (int y=0;y<ipmac.size();y++){
                            if (mac!=ipmac.get(y).getMac().toString().trim()){
                                mac_ip.setIp(ip);
                                mac_ip.setMac(mac);
                                ipmac.add(mac_ip);
                            }
                        }
                    }
                }
            }
            return ipmac;
        } catch (FileNotFoundException e) {

            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }



}

获取IP及mac

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

芝麻猪oo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值