dart 获取手机信息_如何在Dart / Flutter中获得设备IP

在Flutter应用中,用户需要知道其设备的本地IP地址。本文介绍如何通过`dart:io`库和`NetworkInterface.list`方法获取192.168.x.xxx格式的本地IP,而非路由器的公共IP。同时提到了`connectivity`插件用于检查WiFi连接状态。
摘要由CSDN通过智能技术生成

I am currently writing an app where the user needs to know the IP address of their phone/tablet. Where would I find this information?

I only want to know what the local IP address is, such as, 192.168.x.xxx and NOT the public IP address of the router.

So far, I can only seem to find InternetAddress.anyIPv4 and InternetAddress.loopbackIPv4. The loopback address is not what I want as it is 127.0.0.1.

解决方案

I guess you mean the local IP of the currently connected Wifi network, right?

EDIT: NetworkInterface.list is not supported in Android, as later pointed out by Mahesh. Aside from the wifi package suggested in his answer, there's a PR to bring that to the connectivity plugin.

You may also want to check if Wifi is available using the connectivity plugin in flutter/plugins.

Right below there's a simple example of usage of NetworkInferface. B

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值