aboutsummaryrefslogtreecommitdiff
path: root/tests/performance/geo.c
blob: 4c7c138fb123334de6956da530628be362c87e8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <ndpi_api.h>
#include <stdio.h>

int main()
{
    struct ndpi_detection_module_struct *ndpi_info_mod;
    int rc;

    ndpi_info_mod = ndpi_init_detection_module(NULL);
    if (ndpi_info_mod == NULL)
        return 1;

    if(ndpi_finalize_initialization(ndpi_info_mod) != 0)
      return 1;

    rc = ndpi_load_geoip(ndpi_info_mod, "GeoLite2-City.mmdb", "GeoLite2-ASN.mmdb");
    if(rc != 0) {
        fprintf(stderr, "Error loading db files: %d\n", rc);
        return 1;
    }

    char country[50], continent[50], city[50], aso[50];
    u_int32_t asn;

    char *ips[] = {"24.124.1.8", "8.8.8.8", "161.148.164.31", "184.74.73.88"};

    for (u_int8_t i = 0; i < sizeof(ips)/sizeof(ips[0]); i++) {
        ndpi_get_geoip_country_continent_city(ndpi_info_mod, ips[i], country, sizeof(country), continent, sizeof(continent), city, sizeof(city));
        ndpi_get_geoip_aso(ndpi_info_mod, ips[i], aso, sizeof(aso));
        ndpi_get_geoip_asn(ndpi_info_mod, ips[i], &asn);
        printf("%u\n\tCountry: %s\n\tContinent: %s\n\tCity: %s\n\tASN: %u\n\tASO: %s\n\n", i + 1, country, continent, city, asn, aso);
    }

    ndpi_exit_detection_module(ndpi_info_mod);

    return 0;
}