Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This provides a field for storing an IP address or range.
The shorthand widget allows a user to enter the values in any of the following formats:
- example.com
- 10.10.10.10
- 10.10.10.*
- 10.10.10.0 - 10.10.12.255
- 10.10.10.10-20
The CIDR widget allows CIDR inputs only:
- 10.10.10.10/32
Drupal 7 version
The addresses are stored internally as a long, this allows you to do network computations quickly (e.g. is 10.10.10.10 within the range 10.10.10.0 - 10.10.10.50).
This code will find any user entities that have an IP range which includes the visitors current IP address.
$visitor_addr = ip2long($user->hostname);
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'user')
->propertyCondition('status', 1)
->fieldCondition('field_yourfieldname', 'start', $visitor_addr, '<=', 0)
->fieldCondition('field_yourfieldname', 'end', $visitor_addr, '>=', 0)
->execute();
Project information
- Module categories: Site Structure
- 409 sites report using this module
- Created by aidanlis on , updated
- Stable releases for this project are covered by the security advisory policy.
There are currently no supported stable releases.
Releases
7.x-1.0-beta1
released 6 March 2012
Works with Drupal: 7.x
✓ Recommended by the project’s maintainer.
Development version: 7.x-1.x-dev updated 11 Oct 2011 at 12:08 UTC