Posted by aidanlis on October 11, 2011 at 8:20am
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
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.
<?php
$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();
?>Downloads
Recommended releases
Development releases
Project Information
- Maintenance status: Actively maintained
- Development status: Under active development
- Module categories: Fields
- Reported installs: 56 sites currently report using this module. View usage statistics.
- Downloads: 345
- Last modified: March 6, 2012