HarmonyOS 怎样获取蜂窝网络的ip和手机的mac地址?

HarmonyOS
2024-12-19 16:06:35
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

使用getConnectionPropertiesSync返回结果的ConnectionProperties.linkAddresses属性获取蜂窝网络的ip,参考代码:

Text(this.message)
Button('异步获取IP地址')
  .onClick(() => {
    connection.getDefaultNet().then((netHandle: connection.NetHandle) => {
      connection.getConnectionProperties(netHandle).then((data: connection.ConnectionProperties) => {
        console.info("Succeeded to get data: " + JSON.stringify(data));
        this.message = JSON.stringify(data.linkAddresses);
      })
    });
  })

Button('同步获取IP地址')
  .onClick(() => {
    let net = connection.getDefaultNetSync()
    try {
      let properties = connection.getConnectionPropertiesSync(net)
      this.message = JSON.stringify(properties.linkAddresses)
      console.log(JSON.stringify(properties))
      console.log(JSON.stringify(properties.linkAddresses))
    } catch (err) {
      this.message = JSON.stringify(err)
    }
  })
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-net-connection-V5;

获取设备的MAC地址,参考此链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-wifimanager-V5

分享
微博
QQ
微信
回复
2024-12-19 18:38:40
相关问题
如何获取蜂窝网络ip地址
1179浏览 • 1回复 待解决
HarmonyOS 获取设备mac地址ip地址
1441浏览 • 1回复 待解决
HarmonyOS 如何获取ip地址mac地址
1425浏览 • 1回复 待解决
HarmonyOS 如何获取蜂窝IP地址
643浏览 • 1回复 待解决
HarmonyOS 如何获取网络IP地址
961浏览 • 1回复 待解决
HarmonyOS 怎么看手机mac地址
991浏览 • 1回复 待解决
获取本地IP地址方法
3361浏览 • 1回复 待解决
HarmonyOS 如何获取设备ip地址
923浏览 • 1回复 待解决
HarmonyOS 获取本机ip地址
1204浏览 • 1回复 待解决
HarmonyOS 获取IP地址方法
785浏览 • 1回复 待解决
HarmonyOS 获取app网络ip
857浏览 • 1回复 待解决
HarmonyOS 如何获取当前设备 IP 地址
1483浏览 • 1回复 待解决
HarmonyOS app获取本机ip地址
642浏览 • 1回复 待解决
HarmonyOS 需要获取手机ip方法
702浏览 • 1回复 待解决
如何获取正在连接网卡mac地址
2888浏览 • 1回复 待解决