import 'dart:io'; void main() async { final ipConfig = WindowsIpConfig(); final ip = await ipConfig.getIp(); print("Your IPv4 Address: $ip"); } // Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPENABLED=TRUE | Select IPAddress abstract class IpConfig { final String kLoopbackAddress = "127.0.0.1"; String get command; List get arguments; String extractIP(String output); Future getIp() async { final prResult = await Process.run(command, arguments); if (prResult.exitCode == 0) { return extractIP(prResult.stdout); } return ""; } } class WindowsIpConfig extends IpConfig { final _winIpRegExp = RegExp(r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'); @override List get arguments => [ "-c", "Get-WmiObject", " -Class", "Win32_NetworkAdapterConfiguration", "-Filter", "IPENABLED=TRUE", "|", "Select", "IPAddress", ]; @override String get command => "powershell"; @override String extractIP(String output) { return _winIpRegExp.firstMatch(output)!.group(0)!; } }