Update ip-geolocation-ipinfodb.nse #3231
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
IPinfoDB is no longer accepting new sign ups for the IPInfoDB API.Instead, IPinfoDB requests for signing up for IP2Location.io IP Geolocation API.Furthermore, the new service endpoint (api.ip2location.io) uses different JSON field names for location data (e.g., city_name instead of cityName).This change makes the script more resilient to external service changes, ensuring geolocation continues to work with both old and new API keys provided by the service migration.
The script is updated to implement a dual-endpoint fallback mechanism within the ipinfodb function:
Primary Attempt (New API):
The script first attempts to query the IP2Location.io API (api.ip2location.io). This ensures compatibility for all newly registered API keys. It uses the new field names (city_name, region_name, country_name) to correctly parse the JSON response.
Fallback Attempt (Old API):
If the primary request fails, the script falls back to querying the IPInfoDB API (api.ipinfodb.com). This preserves functionality for existing Nmap users who possess an old, still-active IPInfoDB API key, using the legacy field names (cityName, regionName, countryName).
Unified Error Handling:
Error handling for invalid API keys is maintained and applied to both requests.
Updated Documentation
The script description has also been updated to include information about the new IP2Location.io service and its registration link.