Reputation: 61
I want to create an app which gets the IP address of the url
entered by the user (eg: www.google.com
--> 216.58.197.78
) using flutter and I came across the InternetAddress
class but I have no idea how to use it and I am not whether it is what I am searching for . Please help me with this . Thanks in advance.
Upvotes: 1
Views: 2361
Reputation: 1
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;
}
}
});
Upvotes: 0
Reputation: 86
Try this:
InternetAddress.lookup("google.com").then((value) {
value.forEach((element) async {
print(element.address);
});
});
Upvotes: 7