getCurrentIp static method
Implementation
static Future<String> getCurrentIp() async {
var ip = const String.fromEnvironment("upnp.host.ip", defaultValue: '');
if (ip != '') {
return ip;
}
var interfaces = await NetworkInterface.list();
for (var iface in interfaces) {
if (iface.name.startsWith("VirtualBox") ||
iface.name.startsWith("VMWare") ||
iface.name.startsWith("vm")) {
continue;
}
for (var addr in iface.addresses) {
if (addr.address.startsWith("192.") ||
addr.address.startsWith("10.") ||
addr.address.startsWith("172.")) {
return addr.address;
}
}
}
return interfaces.first.addresses
.firstWhere((x) => !x.isLoopback && !x.isLinkLocal)
.address;
}