Skip to content

Commit

Permalink
Added district, asn, and as fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Jun 2, 2023
1 parent 95e7272 commit 4cb900d
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 88 deletions.
2 changes: 1 addition & 1 deletion Developers_Guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ When IP2Location_clear_memory() function is called, and if any other process(es)
After calling IP2Location_clear_memory(), the next call to IP2Location_set_lookup_mode() with IP2LOCATION_SHARED_MEMORY option will result in a new shared memory and will not reuse the old one if one exists and used by any other process. Please refer shm_open and shm_unlink man pages for more info.


Version 8.5.1 07/14/2022
Version 8.6.0 06/02/2023
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ(2.59)
AC_INIT([IP2Loc], [8.5.1], [[email protected]])
AC_INIT([IP2Loc], [8.6.0], [[email protected]])
AM_INIT_AUTOMAKE([ subdir-objects ])

AM_CONFIG_HEADER([config.h])
Expand Down
5 changes: 4 additions & 1 deletion contrib/IP2Location.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%define version 8.5.1
%define version 8.6.0

Name: IP2Location
Summary: C library for mapping IP address to geolocation information
Expand Down Expand Up @@ -122,6 +122,9 @@ install -p data/IPV6-COUNTRY.BIN %{buildroot}%{_datadir}/%{name}/IPV6-COUNTRY.SA


%changelog
* Thu Jun 02 2023 IP2Location <[email protected]> - 8.6.0
- added district, asn, and as fields

* Thu Jul 14 2022 IP2Location <[email protected]> - 8.5.1
- fixed wrong offset for memory modes

Expand Down
3 changes: 3 additions & 0 deletions contrib/IP2Location.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ install -p data/IPV6-COUNTRY.BIN %{buildroot}%{_datadir}/%{name}/IPV6-COUNTRY.SA


%changelog
* Thu Jun 02 2023 IP2Location <[email protected]> - 8.6.0
- added district, asn, and as fields

* Thu Jul 14 2022 IP2Location <[email protected]> - 8.5.1
- fixed wrong offset for memory modes

Expand Down
37 changes: 20 additions & 17 deletions ip2location.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ip2location \- query IP address information from local IP2Location BIN data file

.SH SYNOPSIS
ip2location \-\-data-file [IP2LOCATION BIN DATA PATH] \-\-ip [IP ADDRESS] [OPTIONS]

.SH DESCRIPTION
.PP
ip2location read the IP address, IPv4 or IPv6 address format, and get the information from IP2Location BIN data file for display.
Expand All @@ -31,7 +31,7 @@ Query an IP address and display the country_short result
.TP
ip2location \-\-data-file [IP2LOCATION BIN DATA PATH] \-\-ip [IP ADDRESS] \-\-field country_code,city_name \-\no-heading \-\-format TAB
Query an IP address and display the country_short and city result

.SH OPTIONS
\-b, \-\-bin-version
Print the IP2Location BIN database version.
Expand All @@ -42,25 +42,25 @@ Query an IP address and display the country_short and city result
\-i, \-\-input-file
Specify an input file with IP address list.

\-p, \-\-ip
\-p, \-\-ip
Specify an IP address query (Supported IPv4 and IPv6 address).

\-o, \-\-output-file
\-o, \-\-output-file
Specify output file for query results.

\-f, \-\-format
\-f, \-\-format
Specify output format. Supported formats are:
\- CSV (default)
\- TAB
\- XML
\-h, \-?, \-\-help

\-h, \-?, \-\-help
Display this help file

\-v, \-\-version
\-v, \-\-version
Display the version number

\-e, \-\-field
\-e, \-\-field
Specify the field to be displayed. Supported values are:
\- ip
\- country_code
Expand All @@ -83,16 +83,19 @@ Query an IP address and display the country_short and city result
\- mobile_brand
\- elevation
\- usage_type
\- address_type
\- category

\-n, \-\no-heading
\- address_type
\- category
\- district
\- asn
\- as

\-n, \-\no-heading
Suppress the heading display.

.SH [AUTHORS]
This tool was created by IP2Location (http://www.ip2location.com).
This tool was created by IP2Location (https://www.ip2location.com).

.SH [COPYRIGHT AND LICENSE]
Copyright 2001\-2021 IP2Location.com
Copyright 2001\-2023 IP2Location.com

This tool is licensed under MIT.
23 changes: 19 additions & 4 deletions ip2location.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ static void print_usage(const char *argv0)
" category\n"
" The domain category is based on IAB Tech Lab Content Taxonomy.\n"
"\n"
" district\n"
" District or county name.\n"
"\n"
" as_number\n"
" Autonomous system number (ASN).\n"
"\n"
" as_name\n"
" Autonomous system (AS) name.\n"
"\n"
" -f, --format\n"
" Output format. Supported format:\n"
" - csv (default)\n"
Expand Down Expand Up @@ -108,7 +117,7 @@ static void print_usage(const char *argv0)

static void print_version()
{
printf("IP2Location version 8.0.0\n");
printf("IP2Location version 8.6.0\n");
}

static void print_footer(FILE *fout, const char *field, const char *format)
Expand Down Expand Up @@ -173,6 +182,9 @@ static void print_header(FILE *fout, const char *field, const char *format)
WRITE_HEADER("usage_type");
WRITE_HEADER("address_type");
WRITE_HEADER("category");
WRITE_HEADER("district");
WRITE_HEADER("as_number");
WRITE_HEADER("as_name");

if (*end == ',') {
start = end + 1;
Expand Down Expand Up @@ -263,6 +275,9 @@ static void print_record(FILE *fout, const char *field, IP2LocationRecord *recor
WRITE_FIELD("usage_type", record->usagetype);
WRITE_FIELD("address_type", record->address_type);
WRITE_FIELD("category", record->category);
WRITE_FIELD("district", record->district);
WRITE_FIELD("as_number", record->asn);
WRITE_FIELD("as_name", record->as);

if (*end == ',') {
start = end + 1;
Expand Down Expand Up @@ -293,7 +308,7 @@ int main(int argc, char *argv[])
IP2LocationRecord *record = NULL;
FILE *fout = stdout;

field = "ip,country_code,country_name,region_name,city_name,isp,latitude,longitude,domain,zip_code,time_zone,net_speed,idd_code,area_code,weather_station_code,weather_station_name,mcc,mnc,mobile_brand,elevation,usage_type,address_type,category";
field = "ip,country_code,country_name,region_name,city_name,isp,latitude,longitude,domain,zip_code,time_zone,net_speed,idd_code,area_code,weather_station_code,weather_station_name,mcc,mnc,mobile_brand,elevation,usage_type,address_type,category,district,as_number,as_name";

for (i = 1; i < argc; i++) {
const char *argvi = argv[i];
Expand Down Expand Up @@ -344,7 +359,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Datafile is absent\n");
exit(-1);
}

obj = IP2Location_open((char *)data_file);
if (obj == NULL) {
fprintf(stderr, "Failed to open BIN database %s\n", data_file);
Expand Down Expand Up @@ -403,7 +418,7 @@ int main(int argc, char *argv[])
if (!no_heading) {
print_footer(fout, field, format);
}

IP2Location_close(obj);

return 0;
Expand Down
Loading

0 comments on commit 4cb900d

Please sign in to comment.