【问题标题】:How to collect network information programmatically如何以编程方式收集网络信息
【发布时间】:2014-10-10 09:58:26
【问题描述】:

我正在尝试以编程方式收集网络信息(MAC、IP、DNS 1-2、GateWay、子网掩码),但我确实在处理 DNS 1-2、GateWay 和子网掩码方面遇到了困难。你能帮我解决这个问题吗?

使用 wifimanager,我可以轻松收集 IP 和 MAC 地址。我找不到其他人。

    WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
    String ip = Formatter.formatIpAddress(wm.getConnectionInfo()
            .getIpAddress());
    String mac = wm.getConnectionInfo().getMacAddress();

我也可以从 DhcpInfo 获取所有这些信息,如下所示:

    DhcpInfo d = wm.getDhcpInfo();
    String DNS1 = d.dns1.toString();

但这会返回一些整数值,我无法将其解析为 DNS。

有没有其他方法可以获取 DNS 和网关。

【问题讨论】:

    标签: networking dns dhcp gateway wifimanager


    【解决方案1】:

    我刚刚从以下问题的选定答案中编辑了代码以获取所需的网络信息。这似乎并不聪明,但对我的情况有用。

    How to configue a static IP address, netmask, gateway programmatically on Android 3.x or 4.x

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      相关资源
      最近更新 更多