{"id":2918,"date":"2016-03-16T13:07:23","date_gmt":"2016-03-16T05:07:23","guid":{"rendered":"http:\/\/blog.hoyo.idv.tw\/?p=2918"},"modified":"2016-03-16T17:08:26","modified_gmt":"2016-03-16T09:08:26","slug":"%e5%bb%ba%e7%bd%ae%e8%87%aa%e5%b7%b1%e7%9a%84-ip-%e5%9c%b0%e7%90%86%e4%bd%8d%e7%bd%ae%e6%9f%a5%e8%a9%a2","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=2918","title":{"rendered":"\u5efa\u7f6e\u81ea\u5df1\u7684 IP \u5730\u7406\u4f4d\u7f6e\u67e5\u8a62"},"content":{"rendered":"<h2>IP \u5730\u7406\u8cc7\u6599\u5eab\u4e0b\u8f09<\/h2>\n<ul>\n<li><a href=\"https:\/\/db-ip.com\/db\/\" target=\"_blank\">The DB-IP Database<\/a><\/li>\n<\/ul>\n<p>\u5c07 CSV \u8cc7\u6599\u532f\u5165 MySQL \u8cc7\u6599\u5eab<\/p>\n<pre class=\"nums:true lang:mysql decode:true \">LOAD DATA INFILE '\/tmp\/dbip-city.csv'\r\nINTO TABLE City\r\nFIELDS TERMINATED BY ','\r\nENCLOSED BY '\"'\r\nLINES TERMINATED BY '\\r\\n';<\/pre>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e0b\u8f09\u4e0b\u4f86\u7684 csv \u6a94\u6848\uff0c\u63db\u884c\u662f PC \u683c\u5f0f<\/p>\n<h2>MySQL IPv4 \u7bc4\u570d\u67e5\u8a62<\/h2>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/24179437\/mysql-check-if-an-ip-address-is-in-range\">MySQL check if an IP-address is in range?<\/a><\/li>\n<li><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/miscellaneous-functions.html#function_inet-aton\" target=\"_blank\">MySQL :: MySQL 5.7 Reference Manual :: 12.19 Miscellaneous Functions<\/a><\/li>\n<\/ul>\n<pre class=\"lang:mysql decode:true\">SELECT * \r\nFROM City\r\nWHERE (\r\n    INET_ATON(  \"59.125.207.208\" ) \r\n    BETWEEN INET_ATON( ip_start ) \r\n    AND INET_ATON( ip_end )\r\n)<\/pre>\n<p>INET_ATON() \u662f\u5c08\u70ba IPv4 \u8a2d\u8a08\u7684\u6578\u503c\u8f49\u63db function<\/p>\n<p>--<\/p>\n<h2>\u512a\u5316<\/h2>\n<p>DB-IP \u63d0\u4f9b\u4e86 PHP \u7684\u7bc4\u4f8b\uff0c\u5927\u6982\u9577\u9019\u6a23<\/p>\n<pre class=\"lang:mysql decode:true\">SELECT * \r\nFROM  `City` \r\nWHERE INET_ATON( ip_start ) &gt;= INET_ATON(  \"59.125.207.208\" ) \r\nLIMIT 1<\/pre>\n<p>\u53ef\u4ee5\u5f9e 5 \u79d2\u7684\u67e5\u8a62\u7e2e\u77ed\u5230 1 \u79d2\uff0c\u53ef\u60dc\u7684\u662f\u9084\u662f\u4e0d\u5920\u5feb\uff0c\u66f4\u5feb\u7684\u65b9\u5f0f\u5c31\u662f\u5c07\u554f\u984c\u8f49\u63db\u6210\u6578\u5b78\u984c\uff0c\u4e26\u4e14\u5c07\u9700\u8981\u904b\u7b97\u7684\u5730\u65b9\u4e8b\u5148\u6e96\u5099\u597d<\/p>\n<p>\u589e\u52a0 ip_start_inet \u4ee5\u53ca ip_end_inet \u5169\u500b\u6b04\u4f4d\uff0c\u586b\u5165\u7684\u8cc7\u6599\u70ba INET_ATON() \u8f49\u63db\u5f8c\u7684\u7d50\u679c<\/p>\n<pre class=\"lang:mysql decode:true\">UPDATE City \r\nSET\r\nip_start_inet = INET_ATON( ip_start ),\r\nip_end_inet = INET_ATON( ip_end )<\/pre>\n<p>\u67e5\u8a62\u6642\u4f7f\u7528 &lt;&gt;= \u904b\u7b97\u5143<\/p>\n<pre class=\"lang:mysql decode:true \">SELECT * \r\nFROM  `City` \r\nWHERE ip_start_inet &lt;= INET_ATON(  '211.20.170.215' ) \r\nAND ip_end_inet &gt;= INET_ATON(  '211.20.170.215' )<\/pre>\n<p>\u512a\u5316\u5f8c\u53ef\u5728\u4f4e\u65bc 0.1 \u79d2\u5167\u5b8c\u6210<\/p>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"2918\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,741&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>IP \u5730\u7406\u8cc7\u6599\u5eab\u4e0b\u8f09 The ...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"2918\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;1,741&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2918"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2918"}],"version-history":[{"count":10,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2918\/revisions"}],"predecessor-version":[{"id":2928,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2918\/revisions\/2928"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}