{"id":1228,"date":"2024-08-01T21:23:40","date_gmt":"2024-08-01T13:23:40","guid":{"rendered":"https:\/\/imuslab.com\/wordpress\/?p=1228"},"modified":"2024-08-01T21:23:40","modified_gmt":"2024-08-01T13:23:40","slug":"golang-trie-tree-ip-%e8%bd%89%e5%9c%8b%e7%a2%bc%ef%bc%88country-code%ef%bc%89","status":"publish","type":"post","link":"https:\/\/imuslab.com\/wordpress\/2024\/08\/01\/golang-trie-tree-ip-%e8%bd%89%e5%9c%8b%e7%a2%bc%ef%bc%88country-code%ef%bc%89\/","title":{"rendered":"Golang trie tree IP \u8f49\u570b\u78bc\uff08Country Code\uff09"},"content":{"rendered":"\n<p>\u6700\u8fd1\u56e0\u70ba\u6709\u4eba report \u8aaa Zoraxy \u7684 GeoIP \u529f\u80fd\u4e0d\u6e96\uff0c\u65bc\u662f\u6211\u5728\u91cd\u65b0 review \u9019\u500b geoip database module \u7684\u6642\u5019\u767c\u73fe\uff1a\u6b38\u5e79\u771f\u7684\u5beb\u932f\u4e86\u6b38\uff01\uff1f<\/p>\n\n\n\n<p>\u7136\u5f8c\u5728\u82b1\u4e86\u4e00\u6574\u500b\u665a\u4e0a debug \u4e4b\u5f8c\uff0c\u6211\u7d42\u65bc\u627e\u5230\u6b63\u78ba\u7684\u6f14\u7b97\u6cd5\u548c\u505a\u6cd5\u4e86\u3002\u9019\u88e1\u70ba\u4e86\u7701\u4e0b\u5f8c\u4eba\u5728\u6398\u600e\u6a23\u7528 Golang \u5beb IP \u8f49 Country Code \u7684 resolver\uff0c\u6211\u9019\u88e1\u7d66\u5927\u5bb6\u4e00\u500b\u5feb\u901f\u4e0a\u624b\u7684\u6559\u5b78\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u751a\u9ebc\u662f IP \u8f49 CC\uff1f<\/h2>\n\n\n\n<p>IP \u5c31\u662f IP \u5730\u5740\uff0cCC \u662f country code\uff0c\u6709\u6642\u7a31\u70ba ISO \u570b\u78bc\uff0c\u4f8b\u5982\u8aaa HK TW US GB \u4e4b\u985e\u7684\u3002IPv4 \u8ddf v6 \u7684\u5730\u5740\u5340\u9593\u901a\u5e38\u6703\u88ab assign \u5230\u67d0\u4e00\u500b\u570b\u5bb6\u7684 ISP \u4e0a\uff0c\u800c\u9020\u6210\u8aaa\u53ea\u8981\u77e5\u9053 IP \u5730\u5740\uff0c\u67d0\u7a0b\u5ea6\u4e0a\u4f60\u53ef\u4ee5\u77e5\u9053\u90a3\u500b request \u662f\u5f9e\u54ea\u500b\u570b\u5bb6\u51fa\u4f86\u7684\uff08\u5148\u4e0d\u8981\u8aaa VPN \u6216\u662f ip spoofing \u4e4b\u985e\u7684\u90e8\u5206\u7684\u8a71\uff09\u3002\u53ef\u662f\u7531\u65bc\u6bcf\u9694\u4e00\u6bb5\u6642\u9593\u5c31\u6703\u6709 ISP \u5012\u9589\u3001\u6536\u8cfc\u6216\u662f\u91cd\u7d44\u4e4b\u985e\u7684\uff0c\u6240\u4ee5 IP \u8f49 CC \u7684\u53ef\u9760\u5ea6\u4e26\u975e 100% \u6e96\u78ba\uff0c\u9019\u500b\u6642\u5019\u6211\u5011\u5c31\u9700\u8981\u5f9e\u4e00\u500b\u53ef\u9760\u7684\u4f86\u6e90\u4f86\u5b9a\u671f\u66f4\u65b0\u9019\u4e00\u500b IP range \u5230 CC \u7684 mapping database \u4e86\u3002<\/p>\n\n\n\n<p>\u9019\u500b database \u6700\u51fa\u540d\u7684\u61c9\u8a72\u5c31\u662f maxmind \u7684 geoip database\uff0c\u4eba\u5bb6\u90fd\u6574\u7406\u597d\u6240\u6709\u6578\u64da\u5230\u4e00\u500b database \u6a94\u6848\u88e1\u9762\uff0c\u4e5f\u63d0\u4f9b api \u8b93\u4f60\u53ef\u4ee5\u5feb\u901f\u67e5\u8a62 cc\uff0c\u5f88\u591a\u73fe\u4ee3\u53ea\u6703\u62c9 library \u7684\u958b\u767c\u8005\u901a\u5e38\u5c31\u6703\u76f4\u63a5\u9078\u7528\u5b83\u3002\u7136\u800c\uff0c\u57fa\u65bc\u5b83\u7684 license \u554f\u984c\uff0c\u5982\u679c\u771f\u63a5\u7528\u5b83\u7684\u65b9\u6848\u7684\u8a71\u6703\u8b93\u6388\u6b0a\u548c licensing \u8b8a\u5f97\u4e00\u5718\u4e82\uff0c\u6240\u4ee5\u57fa\u65bc\u591a\u7a2e\u8003\u616e\u4e4b\u4e0b\u9019\u500b\u65b9\u6848\u6211\u5011\u6700\u7d42\u6c92\u6709\u4f7f\u7528\uff0c\u800c\u662f\u4f7f\u7528 Public domain \u6216 CC-0 \u7684\u8cc7\u6599\u4f86\u6e90\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">GeoIP Data Source<\/h3>\n\n\n\n<p>\u6700\u5f8c\u6211\u5011\u4f7f\u7528\u4e86\u4f86\u81ea  GeoFeed + Whois + ASN \uff08CC-0\uff09\u7684\u8cc7\u6599\u4f86\u6e90\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/sapics\/ip-location-db\/tree\/main\/geolite2-country\">https:\/\/github.com\/sapics\/ip-location-db\/tree\/main\/geolite2-country<\/a><\/p>\n\n\n\n<p>\u554f\u984c\u662f\u5b83\u7684\u8cc7\u6599\u8868\u662f\u4e00\u500b csv \u6a94\u6848\uff0c\u5927\u6982\u9577\u9019\u6a23\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> 1.0.0.0,1.0.0.255,AU\n 1.0.1.0,1.0.3.255,CN\n 1.0.4.0,1.0.7.255,AU\n 1.0.8.0,1.0.15.255,CN\n 1.0.16.0,1.0.31.255,JP\n 1.0.32.0,1.0.63.255,CN\n 1.0.64.0,1.0.127.255,JP\n 1.0.128.0,1.0.255.255,TH\n 1.1.0.0,1.1.0.255,CN\n 1.1.1.0,1.1.1.255,AU\n 1.1.2.0,1.1.63.255,CN\n 1.1.64.0,1.1.127.255,JP\n....\n223.255.248.0,223.255.251.255,HK\n223.255.252.0,223.255.253.255,CN\n223.255.254.0,223.255.254.255,SG\n223.255.255.0,223.255.255.255,AU<\/code><\/pre>\n\n\n\n<p>\u90a3\u5047\u8a2d\u6211\u7d66\u4f60\u4e00\u500b ip \u5730\u5740\uff1aA.B.C.D\uff0c\u4f60\u8981\u600e\u6a23\u628a country code \u5f9e csv \u88e1\u9762\u6293\u51fa\u4f86\u5462\uff1f<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6700\u76f4\u89c0\u7684\u7b54\u6848\uff1aO(n)<\/h2>\n\n\n\n<p>\u7576\u7136\u5982\u679c\u6703\u4e00\u9ede\u5beb\u7a0b\u5f0f\u7684\u4eba\u5c31\u6703\u60f3\u5230\uff1a\u90a3\u6211\u628a\u6574\u500b csv loop \u4e00\u6b21\uff0c\u770b\u770b\u54ea\u4e00\u884c\u7684 start ip \u8ddf end ip \u662f\u5305\u542b\u6211\u9019\u500b ip \u5730\u5740\u7684\u5c31\u597d\u4e86\u5566\uff1f\u9019\u500b\u7684\u78ba\u662f\u6211\u5011\u505a\u7d66\u5d4c\u5165\u5f0f\u88dd\u7f6e\u7684\u505a\u6cd5\uff08\u4e0d\u904e\u662f\u70ba\u4e86\u7701 memory\uff09\uff0c\u539f\u7406\u5927\u6982\u9019\u6a23\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func isIPv4InRange(startIP, endIP, testIP string) (bool, error) {\n\tstart := net.ParseIP(startIP)\n\tend := net.ParseIP(endIP)\n\ttest := net.ParseIP(testIP)\n\n\tif start == nil || end == nil || test == nil {\n\t\treturn false, errors.New(\"invalid IP address format\")\n\t}\n\n\tstartUint := ipv4ToUInt32(start)\n\tendUint := ipv4ToUInt32(end)\n\ttestUint := ipv4ToUInt32(test)\n\n\treturn testUint >= startUint &amp;&amp; testUint &lt;= endUint, nil\n}<\/code><\/pre>\n\n\n\n<p>\u7136\u5f8c\u5c31\u771f\u7684\u628a\u6bcf\u4e00\u884c\u8f09\u51fa\u4f86\u6aa2\u67e5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Slow country code lookup for\nfunc (s *Store) slowSearchIpv4(ipAddr string) string {\n\tif isReservedIP(ipAddr) {\n\t\treturn \"\"\n\t}\n\tfor _, ipRange := range s.geodb {\n\t\tstartIp := ipRange&#91;0]\n\t\tendIp := ipRange&#91;1]\n\t\tcc := ipRange&#91;2]\n\n\t\tinRange, _ := isIPv4InRange(startIp, endIp, ipAddr)\n\t\tif inRange {\n\t\t\treturn cc\n\t\t}\n\t}\n\treturn \"\"\n}<\/code><\/pre>\n\n\n\n<p>\u554a\u53ef\u662f\u9019\u771f\u7684\u6162\uff0c\u6240\u4ee5\u5f8c\u4f86\u6211\u5011\u5c0d\u65bc\u8f03\u6b63\u898f\u7684\u4f3a\u670d\u5668\uff0c\u4f7f\u7528\u4e86\u53e6\u4e00\u500b\u8cc7\u6599\u7d50\u69cb\u4f86\u505a\u5230 O(31) \uff08\u6216\u662f IPv6 \u7684 O(128)\uff09 ~ O(1) \u7684\u65b9\u6cd5\u4f86\u505a\uff0c\u5c31\u662f\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Trie Tree<\/h2>\n\n\n\n<p>\u6211\u90fd\u53eb\u5b83 &#8220;Try&#8221; tree\uff0c\u4f46\u662f\u539f\u4f5c\u8005\u53eb\u5b83\u505a &#8220;tree&#8221; tree\uff0c\u4e0d\u904e\u9019\u4e0d\u662f\u91cd\u9ede\uff0c\u91cd\u9ede\u662f\u9019\u6771\u897f\u771f\u7684\u5f88\u6709\u8da3\uff08\uff1f\uff09<\/p>\n\n\n\n<p>\u5728\u6211\u7684 geoIP trie tree \u5b9a\u7fa9\u88e1\u9762\uff0c\u6211\u9996\u5148\u5efa\u7acb\u4e86\u5169\u500b struct\uff1anode \u8ddf head \uff08\u88e1\u9762\u542b\u4e00\u500b node\uff0c\u4e3b\u8981\u662f\u7528\u4f86\u8655\u7406 OOP \u554f\u984c\u800c\u4e0d\u662f trie tree \u672c\u8eab\u9700\u8981\u7684\u6771\u897f\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type trie_Node struct {\n\tchildrens &#91;2]*trie_Node\n\tcc        string\n}\n\n\/\/ Initializing the root of the trie\ntype trie struct {\n\troot *trie_Node\n}<\/code><\/pre>\n\n\n\n<p>\u53e6\u5916\u5c31\u662f\u4e00\u4e9b\u65b9\u4fbf\u4f7f\u7528\u7684 utilities function<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u628a IP \u5730\u5740\u5f9e string \u8f49\u6210 byte\uff0cipv4 \u51fa\u4f86\u6703\u50cf &#91;192,168,1,100] \u9019\u6a23 4 \u500b bytes\nfunc ipToBytes(ip string) &#91;]byte {\n\t\/\/ Parse the IP address string into a net.IP object\n\tparsedIP := net.ParseIP(ip)\n\n\t\/\/ Convert the IP address to a 4-byte slice\n\tipBytes := parsedIP.To4()\n\tif ipBytes == nil {\n\t\t\/\/This is an IPv6 address\n\t\tipBytes = parsedIP.To16()\n\t}\n\n\treturn ipBytes\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u6aa2\u67e5\u662f\u4e0d\u662f\u7279\u6b8a ip \u5730\u5740\uff0c\u5982 loopback \u6216 LAN\nfunc isReservedIP(ip string) bool {\n\tparsedIP := net.ParseIP(ip)\n\tif parsedIP == nil {\n\t\treturn false\n\t}\n\t\/\/ Check if the IP address is a loopback address\n\tif parsedIP.IsLoopback() {\n\t\treturn true\n\t}\n\t\/\/ Check if the IP address is in the link-local address range\n\tif parsedIP.IsLinkLocalUnicast() || parsedIP.IsLinkLocalMulticast() {\n\t\treturn true\n\t}\n\t\/\/Check if the IP is in the reserved private range\n\tif parsedIP.IsPrivate() {\n\t\treturn true\n\t}\n\treturn false\n}<\/code><\/pre>\n\n\n\n<p>\u4e4b\u5f8c\u5c31\u662f tree \u672c\u8eab\u7684\u529f\u80fd\u4e86\u3002\u9996\u5148\u662f\u5efa\u7acb tree \u548c insert tree \u7684 function\u3002 \u9806\u5e36\u4e00\u63d0\uff0c\u56e0\u70ba IPv4 \u662f 32 bit \u800c IPv6 \u662f 128 bit\uff0c\u6240\u4ee5\u5efa\u51fa\u4f86\u5206\u5225\u5c31\u662f\u5169\u9846 32 + 1\u5c64 \u8ddf 128 + 1 \u5c64\u7684\u6a39\uff08\u9019\u88e1 + 1 \u662f root node\uff0c\u5c31\u50cf\u6709\u4e9b\u5730\u65b9\u5730\u9762\u90a3\u5c64\u662f G\/F \u4e5f\u6709\u662f 1\/F \u7684\uff0c\u770b\u4f60\u600e\u6a23\u7b97\u5c64\u6578\uff09 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ inititlaizing a new trie\nfunc newTrie() *trie {\n\tt := new(trie)\n\tt.root = new(trie_Node)\n\treturn t\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/\/ Passing words to trie\nfunc (t *trie) insert(ipAddr string, cc string) {\n\tipBytes := ipToBytes(ipAddr)\n\tcurrent := t.root\n\tfor _, b := range ipBytes {\n\t\t\/\/For each byte in the ip address (4 \/ 16 bytes)\n\t\t\/\/each byte is 8 bit\n\t\tfor j := 7; j >= 0; j-- {\n\t\t\tbit := int(b >> j &amp; 1)\n\t\t\tif current.childrens&#91;bit] == nil {\n\t\t\t\tcurrent.childrens&#91;bit] = &amp;trie_Node{\n\t\t\t\t\tchildrens: &#91;2]*trie_Node{},\n\t\t\t\t\tcc:        cc,\n\t\t\t\t}\n\t\t\t}\n\t\t\tcurrent = current.childrens&#91;bit]\n\t\t}\n\t}\n}<\/code><\/pre>\n\n\n\n<p>\u7136\u5f8c\u5c31\u662f search \u7684 function<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/\/ Initializing the search for word in node\nfunc (t *trie) search(ipAddr string) string {\n\tif isReservedIP(ipAddr) {\n\t\treturn \"\"\n\t}\n\n\tipBytes := ipToBytes(ipAddr)\n\tcurrent := t.root\n\tfor _, b := range ipBytes {\n\t\t\/\/For each byte in the ip address\n\t\t\/\/each byte is 8 bit\n\t\tfor j := 7; j >= 0; j-- {\n\t\t\tbit := int(b >> j &amp; 1)\n\t\t\tif current.childrens&#91;bit] == nil {\n\t\t\t\treturn current.cc\n\t\t\t}\n\t\t\tcurrent = current.childrens&#91;bit]\n\t\t}\n\t}\n\n\tif len(current.childrens) == 0 {\n\t\treturn current.cc\n\t}\n\n\t\/\/Not found\n\treturn \"\"\n}\n<\/code><\/pre>\n\n\n\n<p>\u9019\u5169\u500b function \u6700\u91cd\u8981\u7684\u90e8\u5206\u5927\u6982\u5c31\u662f\u500b for loop<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for j := 7; j >= 0; j-- {\n\tbit := int(b >> j &amp; 1)\n\tif current.childrens&#91;bit] == nil {\n\t\treturn current.cc\n\t}\n\tcurrent = current.childrens&#91;bit]\n}<\/code><\/pre>\n\n\n\n<p>\u5047\u8a2d\u6211\u5011\u7684 IP \u53ea\u6709 4 \u500b bit\uff0c 1.0.0.0 \u5230 1.0.1.1 \u662f\u5c6c\u65bc A \u570b\u5bb6\u7684\uff1b\u800c 1.1.0.0 \u5230 1.1.1.1 \u662f\u5c6c\u65bc B \u570b\u5bb6\u7684\u3002\u8981\u5efa\u9019\u500b tree \u7684\u6642\u5019\u6211\u5011\u8981 insert 4 \u6b21\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>1.0.0.0 -> A<\/li><li>1.0.1.1 -> A<\/li><li>1.1.0.0 -> B<\/li><li>1.1.1.1 -> B<\/li><\/ul>\n\n\n\n<p>\u90a3\u6211\u5011\u7684 trie tree \u5efa\u51fa\u4f86\u6703\u8b8a\u6210\u9019\u6a23\uff0c\u800c\u6bcf\u500b node \u88e1\u9762\u90fd\u5beb\u6709\u76f8\u95dc\u7684 country code\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"602\" src=\"https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247-1024x602.png\" alt=\"\" class=\"wp-image-1229\" srcset=\"https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247-1024x602.png 1024w, https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247-300x176.png 300w, https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247-768x451.png 768w, https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247.png 1178w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u7576\u6211\u5011\u6709\u65b0\u7684 Ip \u9032\u4f86\u7684\u6642\u5019\uff0c\u5047\u8a2d\u9019\u662f 1.0.1.0 \uff08A\uff09\u7684\u6642\u5019\uff0clookup \u904e\u7a0b\u5c31\u6703\u9577\u9019\u6a23\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"584\" src=\"https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247-1-1024x584.png\" alt=\"\" class=\"wp-image-1230\" srcset=\"https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247-1-1024x584.png 1024w, https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247-1-300x171.png 300w, https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247-1-768x438.png 768w, https:\/\/imuslab.com\/wordpress\/wp-content\/uploads\/2024\/08\/\u5716\u7247-1.png 1191w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u4f60\u6703\u767c\u73fe\u5230\u7b2c\u4e09\u500b bit \u7684\u6642\u5019\uff0c\u4e0b\u4e00\u500b node \u627e\u4e0d\u5230\uff0c\u9019\u6a23\u6211\u5011\u5c31\u53ef\u4ee5\u56de\u50b3\u6700\u5f8c\u6709\u627e\u5230\u7684 node \u7684 country code \u56de\u53bb\uff08\u9019\u88e1\u662f A\uff09\uff0c\u9019\u6a23 country code \u5c31\u80fd\u7528\u63a5\u8fd1 O(1) \u7684 time complexity \u88ab\u627e\u5230\u4e86\u3002\u7576\u7136\uff0c\u7f3a\u9ede\u5c31\u662f\u56e0\u70ba\u6574\u500b tree \u90fd\u5728 memory \u88e1\u9762\uff0c\u6240\u4ee5\u9019\u6700\u5c11\u9700\u8981\u63a5\u8fd1 700mb \u7684 RAM \u624d\u80fd\u7528\uff0c\u7d50\u679c\u5982\u679c\u4f60\u662f\u8981\u5728\u5d4c\u5165\u5f0f\u786c\u9ad4\u4e0a\u9762\u8dd1\u9019\u500b\u7684\u8a71\u2026\u984d\u2026\u4f60\u9084\u662f\u56de\u53bb\u7528 for loop \u597d\u4e86\uff08<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5099\u6ce8<\/h3>\n\n\n\n<p>\u9019\u500b\u662f Zoraxy geodb \u7684\u5efa\u6a39 entry point\uff0c\u5982\u679c\u4f60\u662f\u6c92\u770b\u6587\u5b57\u53ea\u4f86\u628a code \u5e79\u8d70\u7684\u8a71\u53ef\u4ee5\u9806\u4fbf\u628a\u9019\u500b\u4e5f\u6284\u4e00\u6284\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Construct the trie data structure for quick lookup\nfunc constrctTrieTree(data &#91;]&#91;]string) *trie {\n\ttt := newTrie()\n\tfor _, entry := range data {\n\t\tstartIp := entry&#91;0]\n\t\tendIp := entry&#91;1]\n\t\tcc := entry&#91;2]\n\t\ttt.insert(startIp, cc)\n\t\ttt.insert(endIp, cc)\n\t}\n\n\treturn tt\n}\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u56e0\u70ba\u6709\u4eba report \u8aaa Zoraxy \u7684 GeoIP \u529f\u80fd\u4e0d\u6e96\uff0c\u65bc\u662f\u6211\u5728\u91cd\u65b0 review \u9019\u500b geoip database module \u7684\u6642\u5019\u767c\u73fe\uff1a\u6b38\u5e79\u771f\u7684\u5beb\u932f\u4e86\u6b38\uff01\uff1f \u7136\u5f8c\u5728\u82b1\u4e86\u4e00\u6574\u500b\u665a\u4e0a debug \u4e4b\u5f8c\uff0c\u6211\u7d42\u65bc\u627e\u5230\u6b63\u78ba\u7684\u6f14\u7b97\u6cd5\u548c\u505a\u6cd5\u4e86\u3002\u9019\u88e1\u70ba\u4e86\u7701\u4e0b\u5f8c\u4eba\u5728\u6398\u600e\u6a23\u7528 Golang \u5beb IP \u8f49 Country Code \u7684 resolver\uff0c\u6211\u9019\u88e1\u7d66\u5927\u5bb6\u4e00\u500b\u5feb\u901f\u4e0a\u624b\u7684\u6559\u5b78\u3002 \u751a\u9ebc\u662f IP \u8f49 CC\uff1f IP \u5c31\u662f IP \u5730\u5740\uff0cCC \u662f country code\uff0c\u6709\u6642\u7a31\u70ba ISO \u570b\u78bc\uff0c\u4f8b\u5982\u8aaa HK TW US GB \u4e4b\u985e\u7684\u3002IPv4 \u8ddf v6 \u7684\u5730\u5740\u5340\u9593\u901a\u5e38\u6703\u88ab assign \u5230\u67d0\u4e00\u500b\u570b\u5bb6\u7684 ISP \u4e0a\uff0c\u800c\u9020\u6210\u8aaa\u53ea\u8981\u77e5\u9053 IP \u5730\u5740\uff0c\u67d0\u7a0b\u5ea6\u4e0a\u4f60\u53ef\u4ee5\u77e5\u9053\u90a3\u500b request \u662f\u5f9e\u54ea\u500b\u570b\u5bb6\u51fa\u4f86\u7684\uff08\u5148\u4e0d\u8981\u8aaa VPN \u6216\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1228","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/posts\/1228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1228"}],"version-history":[{"count":1,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/posts\/1228\/revisions"}],"predecessor-version":[{"id":1231,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/posts\/1228\/revisions\/1231"}],"wp:attachment":[{"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}