#include <stdio.h>
#include <GeoIP.h>
char* get_ip_location(const char* ip) {
const char* db_file = "GeoIP2-City.mmdb";
GeoIP* gi = GeoIP_open(db_file, GEOIP_STANDARD);
GeoIPRecord* record = GeoIP_record_by_name(gi, ip);
const char* location = record->city;
GeoIP_delete(gi);
return location;
}
int main() {
const char* ip_addresses[] = {
"202.102.133.0", "202.102.133.255",
"202.102.135.0", "202.102.136.255",
"202.102.156.34", "202.102.157.255",
"202.102.48.0", "202.102.48.255",
"202.102.49.15", "202.102.51.251",
"202.102.56.0", "202.102.56.255"
};
int i;
for (i = 0; i < 12; i++) {
const char* ip = ip_addresses[i];
char* location = get_ip_location(ip);
printf("%s %s\n", ip, location);
}
return 0;
}