A Django application to retrieve a user's IP address. It aims to provide the best attempt to get the client's IP while handling scenarios involving proxy servers and load balancers. `django-ipware` is a wrapper using `python-ipware` under the hood since version 6.0.0. The current version is 7.0.1, released on April 19, 2024, indicating active development and a regular release cadence with updates to align with new Django and Python versions.
pip install django-ipwareVerified import paths — ran on the pinned version, not inferred.
A simple Django view demonstrating how to retrieve the client's IP address using `get_client_ip`. It returns the IP address and a boolean indicating if it's publicly routable. Remember to pass the `request` object.
Implement additional security measures (firewalls, WAFs) and utilize `proxy_trusted_ips` or `proxy_count` arguments if behind known proxies to improve accuracy. Always validate IP addresses for security-critical operations.
Review `django-ipware` and `python-ipware` documentation for specific API changes if upgrading from versions older than 6.0.0, especially if customizing IP resolution logic beyond basic `get_client_ip` calls. Ensure `python-ipware` is considered a core dependency for recent versions.
If your Django server is behind proxies, configure `get_client_ip(request, proxy_count=N)` with the correct number of proxies or `get_client_ip(request, proxy_trusted_ips=['IP_1', 'IP_2'])` with known trusted proxy IP ranges. Customize `IPWARE_META_PRECEDENCE_ORDER` in settings if non-standard HTTP headers are used.
If using `django-ipware` with `django-axes` or similar packages, ensure `django-ipware` is explicitly installed (`pip install django-ipware`) and review the integrating library's documentation for updated configuration settings (e.g., `AXES_IPWARE_PROXY_ORDER` instead of `AXES_PROXY_ORDER` in `django-axes`).