-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved existing functionality for looking up requesting IP address to …
…use NGINX maps. - Updated ipinfo.conf to remove old location blocks that have been moved to map.conf. Added functionality to allow for looking up IP addresses. - New map.conf that containing maps. - Updated nginx.conf to increase map_hash_bucket_size above default value. - Updated ipinfo.conf to include new location blocks to allow for looking up IP addresses. Updated README to include details on added functionality.
- Loading branch information
Mitchell Kellett
committed
Apr 10, 2023
1 parent
92eff3b
commit b7a782c
Showing
4 changed files
with
120 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
map $1 $lookup_ip { | ||
# Regex to test for IPv4 in NGINX Map | ||
"~(([0-9]{1,3}\.){3}[0-9]{1,3})" $1; | ||
|
||
# Regex to test for IPv6 in NGINX Map | ||
"~(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))" $1; | ||
|
||
default ""; | ||
} | ||
|
||
# If using the requesting IP, use this map block to determine which response to provide. | ||
map $1 $ip_response { | ||
"" "$remote_addr\n$ip_country_code / $ip_country_name\nAS$ip_asn / $ip_aso\n$ip_latitude, $ip_longitude\n$ip_accuracy_radius KM\n$ip_time_zone\n\n$http_user_agent\n"; | ||
"~^ip\/?$" "$remote_addr\n"; | ||
"~^country\/?$" "$ip_country_code / $ip_country_name\n"; | ||
"~^country_code\/?$" "$ip_country_code\n"; | ||
"~^country_name\/?$" "$ip_country_name\n"; | ||
"~^(as\/?$)" "AS$ip_asn / $ip_aso\n"; | ||
"~^(asn\/?$)" "$ip_asn\n"; | ||
"~^(as_desc\/?$)" "$ip_aso\n"; | ||
"~^(user_agent\/?$)" "$http_user_agent\n"; | ||
"~^(json)\/?$" "{\"ip\":\"$remote_addr\",\"country_code\":\"$ip_country_code\",\"country_name\":\"$ip_country_name\",\"asn\":\"$ip_asn\",\"as_desc\":\"$ip_aso\",\"user_agent\":\"$http_user_agent\"}\n"; | ||
|
||
# This section caters to the lookup functionality. | ||
"~^lookup\/?$" "Invalid IP.\n\nPlease enter valid IPv4 or IPv6 address.\n\nExample: /lookup/1.1.1.1 or /lookup/2606:4700:4700:0000:1111\n"; | ||
"~^lookup\/([^\/]+)\/ip\/?$" "$lookup_ip\n"; | ||
"~^lookup\/([^\/]+)\/country\/?$" "$lookup_ip_country_code / $lookup_ip_country_name\n"; | ||
"~^lookup\/([^\/]+)\/country_code\/?$" "$lookup_ip_country_code\n"; | ||
"~^lookup\/([^\/]+)\/country_name\/?$" "$lookup_ip_country_name\n"; | ||
"~^lookup\/([^\/]+)\/as\/?$" "AS$lookup_ip_asn / $lookup_ip_aso\n"; | ||
"~^lookup\/([^\/]+)\/asn\/?$" "$lookup_ip_asn\n"; | ||
"~^lookup\/([^\/]+)\/as_desc\/?$" "$lookup_ip_aso\n"; | ||
"~^lookup\/([^\/]+)\/json\/?$" "{\"ip\":\"$lookup_ip\",\"country_code\":\"$lookup_ip_country_code\",\"country_name\":\"$lookup_ip_country_name\",\"asn\":\"$lookup_ip_asn\",\"as_desc\":\"$lookup_ip_aso\"}\n"; | ||
"~^lookup\/([^\/]+)\/?$" "$lookup_ip\n$lookup_ip_country_code / $lookup_ip_country_name\nAS$lookup_ip_asn / $lookup_ip_aso\n"; | ||
|
||
default "404 not found. See https://github.com/PeterDaveHello/ipinfo.tw \n"; | ||
} | ||
|
||
# If using the requesting IP, use this map block to determine which response type to provide. | ||
map $request_uri $ip_response_content_type { | ||
"~^\/(json)\/?$" application/json; | ||
|
||
# This section caters to the lookup functionality. | ||
"~^\/lookup\/([^\/]+)\/json\/?$" application/json; | ||
|
||
default text/plain; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters