Parse the host
as an IP version 4 (IPv4) address, returning the address
as a list of 4 bytes in network byte order (big endian).
Throws a FormatException if host
is not a valid IPv4 address
representation.
Source
static List<int> parseIPv4Address(String host) { void error(String msg) { throw new FormatException('Illegal IPv4 address, $msg'); } var bytes = host.split('.'); if (bytes.length != 4) { error('IPv4 address should contain exactly 4 parts'); } // TODO(ajohnsen): Consider using Uint8List. return bytes .map((byteString) { int byte = int.parse(byteString); if (byte < 0 || byte > 255) { error('each part must be in the range of `0..255`'); } return byte; }) .toList(); }