|
| 1 | +# IP2Location Ruby API |
| 2 | + |
| 3 | +## IP2Location Class |
| 4 | + |
| 5 | +```{py:class} IP2Location() |
| 6 | +Construct the IP2Location Class. |
| 7 | +``` |
| 8 | + |
| 9 | +```{py:function} open(binPath) |
| 10 | +Load the IP2Location BIN database for lookup. |
| 11 | +
|
| 12 | +:param str binPath: (Required) The file path links to IP2Location BIN databases. |
| 13 | +``` |
| 14 | + |
| 15 | +```{py:function} getAll(ipAddress) |
| 16 | +Retrieve geolocation information for an IP address. |
| 17 | +
|
| 18 | +:param str ipAddress: (Required) The IP address (IPv4 or IPv6). |
| 19 | +:return: Returns the geolocation information in array. Refer below table for the fields avaliable in the array |
| 20 | +:rtype: array |
| 21 | +
|
| 22 | +**RETURN FIELDS** |
| 23 | +
|
| 24 | +| Field Name | Description | |
| 25 | +| ---------------- | ------------------------------------------------------------ | |
| 26 | +| countryShort | Two-character country code based on ISO 3166. | |
| 27 | +| countryLong | Country name based on ISO 3166. | |
| 28 | +| region | Region or state name. | |
| 29 | +| city | City name. | |
| 30 | +| isp | Internet Service Provider or company\'s name. | |
| 31 | +| latitude | City latitude. Defaults to capital city latitude if city is unknown. | |
| 32 | +| longitude | City longitude. Defaults to capital city longitude if city is unknown. | |
| 33 | +| domain | Internet domain name associated with IP address range. | |
| 34 | +| zipCode | ZIP code or Postal code. [172 countries supported](https://www.ip2location.com/zip-code-coverage). | |
| 35 | +| timeZone | UTC time zone (with DST supported). | |
| 36 | +| netSpeed | Internet connection type. | |
| 37 | +| iddCode | The IDD prefix to call the city from another country. | |
| 38 | +| areaCode | A varying length number assigned to geographic areas for calls between cities. [223 countries supported](https://www.ip2location.com/area-code-coverage). | |
| 39 | +| weatherStationCode | The special code to identify the nearest weather observation station. | |
| 40 | +| weatherStationName | The name of the nearest weather observation station. | |
| 41 | +| mcc | Mobile Country Codes (MCC) as defined in ITU E.212 for use in identifying mobile stations in wireless telephone networks, particularly GSM and UMTS networks. | |
| 42 | +| mnc | Mobile Network Code (MNC) is used in combination with a Mobile Country Code(MCC) to uniquely identify a mobile phone operator or carrier. | |
| 43 | +| mobileBrand | Commercial brand associated with the mobile carrier. You may click [mobile carrier coverage](https://www.ip2location.com/mobile-carrier-coverage) to view the coverage report. | |
| 44 | +| elevation | Average height of city above sea level in meters (m). | |
| 45 | +| usageType | Usage type classification of ISP or company. | |
| 46 | +| addressType | IP address types as defined in Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6). | |
| 47 | +| category | The domain category based on [IAB Tech Lab Content Taxonomy](https://www.ip2location.com/free/iab-categories). | |
| 48 | +| district | District or county name. | |
| 49 | +| asn | Autonomous system number (ASN). BIN databases. | |
| 50 | +| as | Autonomous system (AS) name. | |
| 51 | +``` |
| 52 | + |
| 53 | +## IPTools Class |
| 54 | + |
| 55 | +```{py:class} IPTools () |
| 56 | +Initiate IPTools class. |
| 57 | +``` |
| 58 | + |
| 59 | +```{py:function} isIPV4(ipAddress) |
| 60 | +Verify if a string is a valid IPv4 address. |
| 61 | +
|
| 62 | +:param str ipAddress: (Required) IP address. |
| 63 | +:return: Return True if the IP address is a valid IPv4 address or False if it isn't a valid IPv4 address. |
| 64 | +:rtype: boolean |
| 65 | +``` |
| 66 | + |
| 67 | +```{py:function} isIPV6(ipAddress) |
| 68 | +Verify if a string is a valid IPv6 address |
| 69 | +
|
| 70 | +:param str ipAddress: (Required) IP address. |
| 71 | +:return: Return True if the IP address is a valid IPv6 address or False if it isn't a valid IPv6 address. |
| 72 | +:rtype: boolean |
| 73 | +``` |
| 74 | + |
| 75 | +```{py:function} ipV4ToDecimal(ipAddress) |
| 76 | +Translate IPv4 address from dotted-decimal address to decimal format. |
| 77 | +
|
| 78 | +:param str ipAddress: (Required) IPv4 address. |
| 79 | +:return: Return the decimal format of the IPv4 address. |
| 80 | +:rtype: int |
| 81 | +``` |
| 82 | + |
| 83 | +```{py:function} decimalToIPV4(ipNumber) |
| 84 | +Translate IPv4 address from decimal number to dotted-decimal address. |
| 85 | +
|
| 86 | +:param str ip_number: (Required) Decimal format of the IPv4 address. |
| 87 | +:return: Returns the dotted-decimal format of the IPv4 address. |
| 88 | +:rtype: string |
| 89 | +``` |
| 90 | + |
| 91 | +```{py:function} ipV6ToDecimal(ipAddress) |
| 92 | +Translate IPv6 address from hexadecimal address to decimal format. |
| 93 | +
|
| 94 | +:param str ipAddress: (Required) IPv6 address. |
| 95 | +:return: Return the decimal format of the IPv6 address. |
| 96 | +:rtype: int |
| 97 | +``` |
| 98 | + |
| 99 | +```{py:function} decimalToIPV6(ipNumber) |
| 100 | +Translate IPv6 address from decimal number into hexadecimal address. |
| 101 | +
|
| 102 | +:param str ip_number: (Required) Decimal format of the IPv6 address. |
| 103 | +:return: Returns the hexadecimal format of the IPv6 address. |
| 104 | +:rtype: string |
| 105 | +``` |
| 106 | + |
| 107 | +```{py:function} ipV4ToCIDR(ip_from, ip_to) |
| 108 | +Convert IPv4 range into a list of IPv4 CIDR notation. |
| 109 | +
|
| 110 | +:param str ip_from: (Required) The starting IPv4 address in the range. |
| 111 | +:param str ip_to: (Required) The ending IPv4 address in the range. |
| 112 | +:return: Returns the list of IPv4 CIDR notation. |
| 113 | +:rtype: array |
| 114 | +``` |
| 115 | + |
| 116 | +```{py:function} cidrToIPV4(cidr) |
| 117 | +Convert IPv4 CIDR notation into a list of IPv4 addresses. |
| 118 | +
|
| 119 | +:param str cidr: (Required) IPv4 CIDR notation. |
| 120 | +:return: Returns an list of IPv4 addresses. |
| 121 | +:rtype: array |
| 122 | +``` |
| 123 | + |
| 124 | +```{py:function} ipV6ToCIDR(ip_from, ip_to) |
| 125 | +Convert IPv6 range into a list of IPv6 CIDR notation. |
| 126 | +
|
| 127 | +:param str ip_from: (Required) The starting IPv6 address in the range. |
| 128 | +:param str ip_to: (Required) The ending IPv6 address in the range. |
| 129 | +:return: Returns the list of IPv6 CIDR notation. |
| 130 | +:rtype: array |
| 131 | +``` |
| 132 | + |
| 133 | +```{py:function} cidrToIPV6(cidr) |
| 134 | +Convert IPv6 CIDR notation into a list of IPv6 addresses. |
| 135 | +
|
| 136 | +:param str cidr: (Required) IPv6 CIDR notation. |
| 137 | +:return: Returns an list of IPv6 addresses. |
| 138 | +:rtype: array |
| 139 | +``` |
| 140 | + |
| 141 | + |
| 142 | +```{py:function} compressIPV6(ipAddress) |
| 143 | +Compress a IPv6 to shorten the length. |
| 144 | +
|
| 145 | +:param str ipAddress: (Required) IPv6 address. |
| 146 | +:return: Returns the compressed version of IPv6 address. |
| 147 | +:rtype: str |
| 148 | +``` |
| 149 | + |
| 150 | +```{py:function} expandIPV6(ipAddress) |
| 151 | +Expand a shorten IPv6 to full length. |
| 152 | +
|
| 153 | +:param str ipAddress: (Required) IPv6 address. |
| 154 | +:return: Returns the extended version of IPv6 address. |
| 155 | +:rtype: str |
| 156 | +``` |
| 157 | + |
| 158 | +## Country Class |
| 159 | + |
| 160 | +```{py:class} Country(csvFilePath) |
| 161 | +Initiate Ip2locationCountry class and load the IP2Location Country Information CSV file. This database is free for download at <https://www.ip2location.com/free/country-information>. |
| 162 | +
|
| 163 | +:param str csvFilePath: (Required) The file path links to IP2Location Country Information CSV file. |
| 164 | +``` |
| 165 | + |
| 166 | +```{py:function} getCountryInfo(countryCode) |
| 167 | +Provide a ISO 3166 country code to get the country information in array. Will return a full list of countries information if country code not provided. |
| 168 | +
|
| 169 | +:param str countryCode: (Required) The ISO 3166 country code of a country. |
| 170 | +:return: Returns the country information in array. Refer below table for the fields avaliable in the array. |
| 171 | +:rtype: array |
| 172 | +
|
| 173 | +**RETURN FIELDS** |
| 174 | +
|
| 175 | +| Field Name | Description | |
| 176 | +| ---------------- | ------------------------------------------------------------ | |
| 177 | +| countryCode | Two-character country code based on ISO 3166. | |
| 178 | +| countryAlpha3Code | Three-character country code based on ISO 3166. | |
| 179 | +| countryNumericCode | Three-character country code based on ISO 3166. | |
| 180 | +| capital | Capital of the country. | |
| 181 | +| countryDemonym | Demonym of the country. | |
| 182 | +| totalArea | Total area in km{sup}`2`. | |
| 183 | +| population | Population of year 2014. | |
| 184 | +| idd_code | The IDD prefix to call the city from another country. | |
| 185 | +| currencyCode | Currency code based on ISO 4217. | |
| 186 | +| currencyName | Currency name. | |
| 187 | +| currencySymbol | Currency symbol. | |
| 188 | +| langCode | Language code based on ISO 639. | |
| 189 | +| langName | Language name. | |
| 190 | +| cctld | Country-Code Top-Level Domain. | |
| 191 | +``` |
| 192 | + |
| 193 | +## Region Class |
| 194 | + |
| 195 | +```{py:class} Region(csvFilePath) |
| 196 | +Initiate Ip2locationRegion class and load the IP2Location ISO 3166-2 Subdivision Code CSV file. This database is free for download at <https://www.ip2location.com/free/iso3166-2> |
| 197 | +
|
| 198 | +:param str csvFilePath: (Required) The file path links to IP2Location ISO 3166-2 Subdivision Code CSV file. |
| 199 | +``` |
| 200 | + |
| 201 | +```{py:function} getRegionCode(countryCode, regionName) |
| 202 | +Provide a ISO 3166 country code and the region name to get ISO 3166-2 subdivision code for the region. |
| 203 | +
|
| 204 | +:param str countryCode: (Required) Two-character country code based on ISO 3166. |
| 205 | +:param str regionName: (Required) Region or state name. |
| 206 | +:return: Returns the ISO 3166-2 subdivision code of the region. |
| 207 | +:rtype: str |
| 208 | +``` |
0 commit comments