├── ip2region.db ├── test.php ├── composer.json ├── README.md ├── Ip2Region.php └── LICENSE.md /ip2region.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/ip2region/master/ip2region.db -------------------------------------------------------------------------------- /test.php: -------------------------------------------------------------------------------- 1 | btreeSearch($ip); 9 | 10 | var_export($info, true); 11 | 12 | // array ( 13 | // 'city_id' => 2163, 14 | // 'region' => '中国|华南|广东省|深圳市|鹏博士', 15 | // ) -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "library", 3 | "name": "zoujingli/ip2region", 4 | "homepage": "https://github.com/zoujingli/Ip2Region", 5 | "description": "Ip2Region", 6 | "license": "Apache 2.0", 7 | "keywords": [ 8 | "Ip2Region" 9 | ], 10 | "require": { 11 | "php": ">=5.3.3" 12 | }, 13 | "autoload": { 14 | "classmap": [ 15 | "Ip2Region.php" 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Latest Stable Version](https://poser.pugx.org/zoujingli/ip2region/v/stable)](https://packagist.org/packages/zoujingli/ip2region) 2 | [![Total Downloads](https://poser.pugx.org/zoujingli/ip2region/downloads)](https://packagist.org/packages/zoujingli/ip2region) 3 | [![Latest Unstable Version](https://poser.pugx.org/zoujingli/ip2region/v/unstable)](https://packagist.org/packages/zoujingli/ip2region) 4 | [![License](https://poser.pugx.org/zoujingli/ip2region/license)](https://packagist.org/packages/zoujingli/ip2region) 5 | 6 | 7 | 本库基于 [ip2region](https://github.com/lionsoul2014/ip2region) ,简单整合方便使用`composer`来管理。 8 | -- 9 | 10 | [ip2region](https://github.com/lionsoul2014/ip2region) - 最自由的ip地址查询库,ip到地区的映射库,提供Binary,B树和纯内存三种查询算法,妈妈再也不用担心我的ip地址定位。 11 | 12 | ### 1. 99.9%准确率,定时更新: 13 | 14 | 数据聚合了一些知名ip到地名查询提供商的数据,这些是他们官方的的准确率,经测试着实比纯真啥的准确多了。
15 | 每次聚合一下数据需要1-2天,会不定时更新。 16 | 17 | ### 2. 标准化的数据格式: 18 | 19 | 每条ip数据段都固定了格式:_城市Id|国家|区域|省份|城市|ISP_ 20 | 21 | 只有中国的数据精确到了城市,其他国家只能定位到国家,后前的选项全部是0,已经包含了全部你能查到的大大小小的国家。 22 | (请忽略前面的城市Id,个人项目需求) 23 | 24 | ### 3. 体积小: 25 | 26 | 数据库文件ip2region.db只有1.5M 27 | 28 | ### Composer 安装 29 | 30 | ``` 31 | composer require zoujingli/ip2region 32 | ``` 33 | 34 | ### ip2region 使用 35 | ```php 36 | 37 | $ip2region = new Ip2Region(); 38 | 39 | $ip = '101.105.35.57'; 40 | 41 | $info = $ip2region->btreeSearch($ip); 42 | 43 | var_export($info, true); 44 | 45 | // array ( 46 | // 'city_id' => 2163, 47 | // 'region' => '中国|华南|广东省|深圳市|鹏博士', 48 | // ) 49 | 50 | ``` 51 | -------------------------------------------------------------------------------- /Ip2Region.php: -------------------------------------------------------------------------------- 1 | 6 | * @date 2015-10-29 7 | */ 8 | 9 | defined('INDEX_BLOCK_LENGTH') or define('INDEX_BLOCK_LENGTH', 12); 10 | defined('TOTAL_HEADER_LENGTH') or define('TOTAL_HEADER_LENGTH', 4096); 11 | 12 | class Ip2Region { 13 | /** 14 | * db file handler 15 | */ 16 | private $dbFileHandler = NULL; 17 | 18 | /** 19 | * header block info 20 | */ 21 | private $HeaderSip = NULL; 22 | private $HeaderPtr = NULL; 23 | private $headerLen = 0; 24 | 25 | /** 26 | * super block index info 27 | */ 28 | private $firstIndexPtr = 0; 29 | private $lastIndexPtr = 0; 30 | private $totalBlocks = 0; 31 | 32 | /** 33 | * for memory mode only 34 | * the original db binary string 35 | */ 36 | private $dbBinStr = NULL; 37 | private $dbFile = NULL; 38 | 39 | /** 40 | * construct method 41 | * 42 | * @param ip2regionFile 43 | */ 44 | public function __construct($ip2regionFile = null) { 45 | $this->dbFile = is_null($ip2regionFile) ? __DIR__ . '/ip2region.db' : $ip2regionFile; 46 | } 47 | 48 | /** 49 | * all the db binary string will be loaded into memory 50 | * then search the memory only and this will a lot faster than disk base search 51 | * @Note: 52 | * invoke it once before put it to public invoke could make it thread safe 53 | * 54 | * @param $ip 55 | */ 56 | public function memorySearch($ip) { 57 | //check and load the binary string for the first time 58 | if ($this->dbBinStr == NULL) { 59 | $this->dbBinStr = file_get_contents($this->dbFile); 60 | if ($this->dbBinStr == false) { 61 | throw new Exception("Fail to open the db file {$this->dbFile}"); 62 | } 63 | 64 | $this->firstIndexPtr = self::getLong($this->dbBinStr, 0); 65 | $this->lastIndexPtr = self::getLong($this->dbBinStr, 4); 66 | $this->totalBlocks = ($this->lastIndexPtr - $this->firstIndexPtr) / INDEX_BLOCK_LENGTH + 1; 67 | } 68 | 69 | if (is_string($ip)) $ip = self::safeIp2long($ip); 70 | 71 | //binary search to define the data 72 | $l = 0; 73 | $h = $this->totalBlocks; 74 | $dataPtr = 0; 75 | while ($l <= $h) { 76 | $m = (($l + $h) >> 1); 77 | $p = $this->firstIndexPtr + $m * INDEX_BLOCK_LENGTH; 78 | $sip = self::getLong($this->dbBinStr, $p); 79 | if ($ip < $sip) { 80 | $h = $m - 1; 81 | } else { 82 | $eip = self::getLong($this->dbBinStr, $p + 4); 83 | if ($ip > $eip) { 84 | $l = $m + 1; 85 | } else { 86 | $dataPtr = self::getLong($this->dbBinStr, $p + 8); 87 | break; 88 | } 89 | } 90 | } 91 | 92 | //not matched just stop it here 93 | if ($dataPtr == 0) return NULL; 94 | 95 | //get the data 96 | $dataLen = (($dataPtr >> 24) & 0xFF); 97 | $dataPtr = ($dataPtr & 0x00FFFFFF); 98 | 99 | return array( 100 | 'city_id' => self::getLong($this->dbBinStr, $dataPtr), 101 | 'region' => substr($this->dbBinStr, $dataPtr + 4, $dataLen - 4) 102 | ); 103 | } 104 | 105 | /** 106 | * get the data block throught the specifield ip address or long ip numeric with binary search algorithm 107 | * 108 | * @param ip 109 | * @return mixed Array or NULL for any error 110 | */ 111 | public function binarySearch($ip) { 112 | //check and conver the ip address 113 | if (is_string($ip)) $ip = self::safeIp2long($ip); 114 | if ($this->totalBlocks == 0) { 115 | //check and open the original db file 116 | if ($this->dbFileHandler == NULL) { 117 | $this->dbFileHandler = fopen($this->dbFile, 'r'); 118 | if ($this->dbFileHandler == false) { 119 | throw new Exception("Fail to open the db file {$this->dbFile}"); 120 | } 121 | } 122 | 123 | fseek($this->dbFileHandler, 0); 124 | $superBlock = fread($this->dbFileHandler, 8); 125 | 126 | $this->firstIndexPtr = self::getLong($superBlock, 0); 127 | $this->lastIndexPtr = self::getLong($superBlock, 4); 128 | $this->totalBlocks = ($this->lastIndexPtr - $this->firstIndexPtr) / INDEX_BLOCK_LENGTH + 1; 129 | } 130 | 131 | //binary search to define the data 132 | $l = 0; 133 | $h = $this->totalBlocks; 134 | $dataPtr = 0; 135 | while ($l <= $h) { 136 | $m = (($l + $h) >> 1); 137 | $p = $m * INDEX_BLOCK_LENGTH; 138 | 139 | fseek($this->dbFileHandler, $this->firstIndexPtr + $p); 140 | $buffer = fread($this->dbFileHandler, INDEX_BLOCK_LENGTH); 141 | $sip = self::getLong($buffer, 0); 142 | if ($ip < $sip) { 143 | $h = $m - 1; 144 | } else { 145 | $eip = self::getLong($buffer, 4); 146 | if ($ip > $eip) { 147 | $l = $m + 1; 148 | } else { 149 | $dataPtr = self::getLong($buffer, 8); 150 | break; 151 | } 152 | } 153 | } 154 | 155 | //not matched just stop it here 156 | if ($dataPtr == 0) return NULL; 157 | 158 | 159 | //get the data 160 | $dataLen = (($dataPtr >> 24) & 0xFF); 161 | $dataPtr = ($dataPtr & 0x00FFFFFF); 162 | 163 | fseek($this->dbFileHandler, $dataPtr); 164 | $data = fread($this->dbFileHandler, $dataLen); 165 | 166 | return array( 167 | 'city_id' => self::getLong($data, 0), 168 | 'region' => substr($data, 4) 169 | ); 170 | } 171 | 172 | /** 173 | * get the data block associated with the specifield ip with b-tree search algorithm 174 | * @Note: not thread safe 175 | * 176 | * @param ip 177 | * @return Mixed Array for NULL for any error 178 | */ 179 | public function btreeSearch($ip) { 180 | if (is_string($ip)) $ip = self::safeIp2long($ip); 181 | 182 | //check and load the header 183 | if ($this->HeaderSip == NULL) { 184 | //check and open the original db file 185 | if ($this->dbFileHandler == NULL) { 186 | $this->dbFileHandler = fopen($this->dbFile, 'r'); 187 | if ($this->dbFileHandler == false) { 188 | throw new Exception("Fail to open the db file {$this->dbFile}"); 189 | } 190 | } 191 | 192 | fseek($this->dbFileHandler, 8); 193 | $buffer = fread($this->dbFileHandler, TOTAL_HEADER_LENGTH); 194 | 195 | //fill the header 196 | $idx = 0; 197 | $this->HeaderSip = array(); 198 | $this->HeaderPtr = array(); 199 | for ($i = 0; $i < TOTAL_HEADER_LENGTH; $i += 8) { 200 | $startIp = self::getLong($buffer, $i); 201 | $dataPtr = self::getLong($buffer, $i + 4); 202 | if ($dataPtr == 0) break; 203 | 204 | $this->HeaderSip[] = $startIp; 205 | $this->HeaderPtr[] = $dataPtr; 206 | $idx++; 207 | } 208 | 209 | $this->headerLen = $idx; 210 | } 211 | 212 | //1. define the index block with the binary search 213 | $l = 0; 214 | $h = $this->headerLen; 215 | $sptr = 0; 216 | $eptr = 0; 217 | while ($l <= $h) { 218 | $m = (($l + $h) >> 1); 219 | 220 | //perfetc matched, just return it 221 | if ($ip == $this->HeaderSip[$m]) { 222 | if ($m > 0) { 223 | $sptr = $this->HeaderPtr[$m - 1]; 224 | $eptr = $this->HeaderPtr[$m]; 225 | } else { 226 | $sptr = $this->HeaderPtr[$m]; 227 | $eptr = $this->HeaderPtr[$m + 1]; 228 | } 229 | 230 | break; 231 | } 232 | 233 | //less then the middle value 234 | if ($ip < $this->HeaderSip[$m]) { 235 | if ($m == 0) { 236 | $sptr = $this->HeaderPtr[$m]; 237 | $eptr = $this->HeaderPtr[$m + 1]; 238 | break; 239 | } else if ($ip > $this->HeaderSip[$m - 1]) { 240 | $sptr = $this->HeaderPtr[$m - 1]; 241 | $eptr = $this->HeaderPtr[$m]; 242 | break; 243 | } 244 | $h = $m - 1; 245 | } else { 246 | if ($m == $this->headerLen - 1) { 247 | $sptr = $this->HeaderPtr[$m - 1]; 248 | $eptr = $this->HeaderPtr[$m]; 249 | break; 250 | } else if ($ip <= $this->HeaderSip[$m + 1]) { 251 | $sptr = $this->HeaderPtr[$m]; 252 | $eptr = $this->HeaderPtr[$m + 1]; 253 | break; 254 | } 255 | $l = $m + 1; 256 | } 257 | } 258 | 259 | //match nothing just stop it 260 | if ($sptr == 0) return NULL; 261 | 262 | //2. search the index blocks to define the data 263 | $blockLen = $eptr - $sptr; 264 | fseek($this->dbFileHandler, $sptr); 265 | $index = fread($this->dbFileHandler, $blockLen + INDEX_BLOCK_LENGTH); 266 | 267 | $dataptr = 0; 268 | $l = 0; 269 | $h = $blockLen / INDEX_BLOCK_LENGTH; 270 | while ($l <= $h) { 271 | $m = (($l + $h) >> 1); 272 | $p = (int)($m * INDEX_BLOCK_LENGTH); 273 | $sip = self::getLong($index, $p); 274 | if ($ip < $sip) { 275 | $h = $m - 1; 276 | } else { 277 | $eip = self::getLong($index, $p + 4); 278 | if ($ip > $eip) { 279 | $l = $m + 1; 280 | } else { 281 | $dataptr = self::getLong($index, $p + 8); 282 | break; 283 | } 284 | } 285 | } 286 | 287 | //not matched 288 | if ($dataptr == 0) return NULL; 289 | 290 | //3. get the data 291 | $dataLen = (($dataptr >> 24) & 0xFF); 292 | $dataPtr = ($dataptr & 0x00FFFFFF); 293 | 294 | fseek($this->dbFileHandler, $dataPtr); 295 | $data = fread($this->dbFileHandler, $dataLen); 296 | 297 | return array( 298 | 'city_id' => self::getLong($data, 0), 299 | 'region' => substr($data, 4) 300 | ); 301 | } 302 | 303 | 304 | /** 305 | * safe self::safeIp2long function 306 | * 307 | * @param ip 308 | * */ 309 | public static function safeIp2long($ip) { 310 | $ip = ip2long($ip); 311 | 312 | // convert signed int to unsigned int if on 32 bit operating system 313 | if ($ip < 0 && PHP_INT_SIZE == 4) { 314 | $ip = sprintf("%u", $ip); 315 | } 316 | 317 | return $ip; 318 | } 319 | 320 | 321 | /** 322 | * read a long from a byte buffer 323 | * 324 | * @param b 325 | * @param offset 326 | */ 327 | public static function getLong($b, $offset) { 328 | $val = ( 329 | (ord($b[$offset++])) | 330 | (ord($b[$offset++]) << 8) | 331 | (ord($b[$offset++]) << 16) | 332 | (ord($b[$offset]) << 24) 333 | ); 334 | 335 | // convert signed int to unsigned int if on 32 bit operating system 336 | if ($val < 0 && PHP_INT_SIZE == 4) { 337 | $val = sprintf("%u", $val); 338 | } 339 | 340 | return $val; 341 | } 342 | 343 | /** 344 | * destruct method, resource destroy 345 | */ 346 | public function __destruct() { 347 | if ($this->dbFileHandler != NULL) { 348 | fclose($this->dbFileHandler); 349 | } 350 | 351 | $this->dbBinStr = NULL; 352 | $this->HeaderSip = NULL; 353 | $this->HeaderPtr = NULL; 354 | } 355 | } 356 | 357 | ?> 358 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | ========================================================================== 204 | The following license applies to the ip2region library 205 | -------------------------------------------------------------------------- 206 | Copyright (c) 2015 Lionsoul 207 | 208 | Permission is hereby granted, free of charge, to any person obtaining 209 | a copy of this software and associated documentation files (the 210 | "Software"), to deal in the Software without restriction, including 211 | without limitation the rights to use, copy, modify, merge, publish, 212 | distribute, sublicense, and/or sell copies of the Software, and to 213 | permit persons to whom the Software is furnished to do so, subject to 214 | the following conditions: 215 | 216 | The above copyright notice and this permission notice shall be 217 | included in all copies or substantial portions of the Software. 218 | 219 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 220 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 221 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 222 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 223 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 224 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 225 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 226 | --------------------------------------------------------------------------------