querySpecificIp static method
Query information for a specific IP address.
The ip parameter should be a valid IPv4 or IPv6 address.
Optionally specify the response format (defaults to JSON).
Returns an IpInfo object for JSON format, or a raw response string for other formats.
final info = await IpQuery.querySpecificIp('8.8.8.8');
print('Google DNS is in: ${info.location?.country}');
Implementation
static Future<dynamic> querySpecificIp(String ip,
{IpQueryFormat format = IpQueryFormat.json}) async {
final response = await http
.get(Uri.parse(_baseUrl + ip + '?format=${_formatToString(format)}'));
if (response.statusCode != 200) {
throw Exception('Failed to fetch IP info: ${response.statusCode}');
}
if (format == IpQueryFormat.json) {
return IpInfo.fromJson(jsonDecode(response.body));
} else {
return response.body;
}
}