queryBulkIps static method
Query information for multiple IP addresses (bulk).
The ips parameter should be a list of valid IP addresses.
Optionally specify the response format (defaults to JSON).
Returns a List<IpInfo> for JSON format, or a raw response string for other formats.
final results = await IpQuery.queryBulkIps(['8.8.8.8', '1.1.1.1']);
for (var info in results) {
print('${info.ip} is in ${info.location?.country}');
}
Implementation
static Future<dynamic> queryBulkIps(List<String> ips,
{IpQueryFormat format = IpQueryFormat.json}) async {
final joined = ips.join(',');
final response = await http.get(
Uri.parse(_baseUrl + joined + '?format=${_formatToString(format)}'));
if (response.statusCode != 200) {
throw Exception('Failed to fetch bulk IP info: ${response.statusCode}');
}
if (format == IpQueryFormat.json) {
final List<dynamic> data = jsonDecode(response.body);
return data.map((e) => IpInfo.fromJson(e)).toList();
} else {
return response.body;
}
}