Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

IP Address Lookup

No security coverage

Part of the IP ecosystem · 8 projects

View on drupal.org

This module helps in integration of IP Address Lookup (https://ipapi.co/#api).

ipapi.co provides a REST API to find the location of an IP address.

Specifically, you can get the following information for any IP address:
city, region (name & code), country (name & code), continent, postal code / zip code, latitude, longitude, timezone, utc offset, european union (EU) membership, country calling code, country capital, country tld (top-level domain), currency (name & code), area & population of the country, languages spoken, asn, organization and hostname*.

When you are using this api on client side, it work perfectly using the public IP.

GET https://ipapi.co/{format}/
Like GET https://ipapi.co/json/

When it comes to use at server side, it start giving response as per server IP

This module helps you in working with client side with some back-end configuration. It provide services which you can easily use in getting IP address details.


Step Involve

  1. Install module as you do.
  2. If you have API you can add in the configuration /admin/config/services/ip_address_lookup
  3. There is also a debug option which you can used to check the response for specifit IP address.


Function to Use

  1. getCountry() : This will return the Country Name
  2. getCity() : This will return the City Name
  3. getCountryCode() : This will return the Country Code
  4. getRegion() : Get region/state short code (FIPS or ISO)
  5. getLatitude() : Get latitude
  6. getLongitude() : Get longitude.
  7. getPostal() : Get zip/Postal code.
  8. getTimezone() : Get timezone


How to use service in code

  1. getCountry()
    $country = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCountry();
  2. getCity()
    $city = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCity();
  3. getCountryCode()
    $country_code = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCountryCode();
  4. getRegion()
    $region = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getRegion();
  5. getLatitude()
    $lat = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getLatitude();
  6. getLongitude()
    $long = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getLongitude();
  7. getPostal()
    $postal = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getPostal();
  8. getTimezone()
    $timezone = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getTimezone();

If you want to get all data together then just call

 \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail();

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Apr 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.x-dev Dev Apr 24, 2023