All Products
Search
Document Center

IP address resolution functions

Last Updated: Jun 05, 2019

ip2region

  1. ip2region(ip, level, lang)
  • Function description: This function obtains the country/region, province, and city where the IP address resides, and supports language setting.

  • Return value type: VARCHAR

  • Parameter description:

    • ip: the IP address you want to query

    • level: four options, namely, country, province, city, and isp.

    • lang: CN or EN, which means that the return value is displayed in Chinese or English

  • For example:

    1. select ip2region('31.13.79.1', 'country', 'CN')
    2. + --------------------------------------------- +
    3. | India |
    4. select ip2region('31.13.79.1', 'country', 'EN')
    5. + --------------------------------------------- +
    6. | India |

ip_country/ip_province/ip_city/ip_isp

ip_country/ip_province/ip_city/ip_isp is a simple application of the ip2region function.

  • ip_country: obtains the country/region where the IP address resides.

  • ip_province: obtains the province where the IP address resides.

  • ip_city: obtains the city where the IP address resides.

  • ip_isp: obtains the Internet service provider (ISP) that allocates the IP address.

  1. select ip_country('31.13.79.1')
  2. +---------------------------+
  3. | India |
  4. select ip_country('31.13.79.1','EN')
  5. +-----------------------------+
  6. | India |
  7. select ip_province('31.13.79.1')
  8. +-----------------------------+
  9. |Maharashtra |
  10. select ip_province('31.13.79.1','EN')
  11. +------------------------------+
  12. |Maharashtra |
  13. select ip_city('31.13.79.1')
  14. +------------------------------+
  15. |Mumbai |
  16. select ip_city('31.13.79.1','EN')
  17. +------------------------------+
  18. |Mumbai |
  19. select ip_isp('115.239.210.27')
  20. +------------------------------+
  21. |China Telecom |
  22. select ip_isp('115.239.210.27','EN')
  23. +-------------------------------+
  24. |ChinaTelecom |

ip2long

  1. ip2long(ip)
  • Function description: This function converts an IP address into a digit.

  • Return value type: BIGINT

  • For example:

    1. select ip2long('115.239.210.27')
    2. +----------------------------+
    3. |1945096731 |

long2ip

  1. long2ip(longVal)
  • Function Description: This function converts a number into an IP address.

  • Return value type: VARCHAR

  • Parameter description: longVal is a BIGINT value.

  • For example:

    1. select long2ip(1945096731)
    2. +--------------------+
    3. | 115.239.210.27 |