我想创建一个应用程序,它可以获取用户输入的url的IP地址(例如:www.google.com--> 216.58.197.78)使用flutter,我遇到了InternetAddress类,但我不知道如何使用它,我不知道它是否是我正在寻找的。请帮我拿这个。先谢了。
url
www.google.com
216.58.197.78
InternetAddress
kxxlusnw1#
试试这个:
InternetAddress.lookup("google.com").then((value) { value.forEach((element) async { print(element.address); }); });
ws51t4hk2#
使用ipfinder
import 'package:ipfinder/ipfinder.dart'; void main() async { Ipfinder ipfinder = Ipfinder("YOUR_TOKEN_GOES_HERE"); IpResponse ip = await ipfinder.getAddressInfo("1.0.0.0"); print(ip.toJson()); // print json data }
qlvxas9a3#
conan@conan-ubuntu-desktop:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.3 LTS Release: 22.04 Codename: jammy conan@conan-ubuntu-desktop:~$ flutter --version Flutter 3.13.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision efbf63d9c6 (2주 전) • 2023-08-15 21:05:06 -0500 Engine • revision 1ac611c64e Tools • Dart 3.1.0 • DevTools 2.25.0
String sIP = ""; InternetAddress.lookup("google.com").then((value) { for (var element in value) { if (element.type==InternetAddressType.IPv4) { //<-- IPv6, unix sIP = element.address; break; } } });
3条答案
按热度按时间kxxlusnw1#
试试这个:
ws51t4hk2#
使用ipfinder
qlvxas9a3#