ofirgalcon / ip_location
IP location module for MunkiReport (ipinfo.io).
Requires
None
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Provides IP location information for clients, including geographical and organizational data. The module collects location data when the client's WAN IP address changes and displays it in a user-friendly format with relative timestamps showing how long ago the IP address last changed.
Data can be viewed under the IP Location tab on the client details page or using the IP Location list view.
Installation
-
Copy the module to your MunkiReport modules directory:
cp -r ip_location /path/to/munkireport/local/modules/
-
Run the database migration:
php /path/to/munkireport/index.php migrate
Configuration
This module uses the ipinfo.io API to gather location data. You will need to:
-
Register for an API token at https://ipinfo.io/
-
Store the token in a preferences plist (client script Version 2+):
sudo defaults write /Library/Preferences/com.ofirgalcon.ip_location.plist Token "your_token_here"Legacy installs that already use
/Library/Preferences/com.gal.iplocation.plistkeep working; the script reads Token/LastIP from that file if the new domain has no Token yet. -
Deploy the script to your managed clients (or rebuild/redistribute the MunkiReport client package so
scripts/ip_location.shis installed). -
Enable the
ip_locationmodule on the server and run migrations.
How It Works
The module works by:
- IP Detection: The script detects the client's current WAN IP address
- Change Detection: Only fetches new location data when the IP address changes
- Data Collection: Uses the ipinfo.io API to get geographical and organizational data
- Caching: Stores the last known IP to avoid unnecessary API calls
- Reporting: Sends the data to MunkiReport for display
The script includes intelligent caching to minimize API calls and only updates location data when the client's IP address actually changes.
Table Schema
- id - int - Primary key
- serial_number - varchar(255) - Unique client identifier
- ip - varchar(255) - IP address
- hostname - varchar(255) - Hostname
- city - varchar(255) - City
- region - varchar(255) - Region/State/Province
- country - varchar(255) - Country
- location - varchar(255) - Geographical location coordinates
- organization - varchar(255) - Organization/ISP
- postal_code - varchar(255) - Postal/ZIP code
- timezone - varchar(255) - Timezone
- last_update - bigInteger - Unix timestamp showing when the IP address last changed (formatted as relative time in listings)
Features
- Smart Caching: Only updates when IP address changes
- Error Handling: Robust error handling for network issues
- Data Validation: Validates IP addresses and API responses
- Relative Timestamps: Displays "time since last IP change" in listing views
- Comprehensive Data: Includes geographical, organizational, and timezone information
Widgets
This module provides the following widgets:
- IP Location City
- IP Location Region
- IP Location Country
- IP Location Organization
- IP Location Postal Code
- IP Location Timezone
Usage
The module will automatically collect data when:
- The script runs and detects a new IP address
- Force refresh is enabled via
FORCE_REFRESH=1environment variable - The client's WAN IP address changes
Data is displayed in the MunkiReport interface with:
- Relative timestamps showing how long ago the IP address last changed (e.g., "2 hours ago", "3 days ago")
- Full date/time available as tooltips
- Organized geographical and organizational information
Troubleshooting
Script not running: Ensure the script has execute permissions and is properly deployed to clients.
No data appearing: Check that the API token is correctly configured and the script has network access.
API errors: Verify your ipinfo.io token is valid and has sufficient quota.
Permission errors: The script needs to read the Token and write LastIP under /Library/Preferences/com.ofirgalcon.ip_location.plist (or the legacy com.gal.iplocation plist if that is where the Token still lives).
Testing
You can test the script manually:
# Test with a specific IP FORCE_REFRESH=1 wanIP=8.8.8.8 ./ip_location.sh # Check the output cat cache/ip_location.txt
The script will output location data in the format expected by MunkiReport.