{"id":249,"date":"2021-08-03T09:12:00","date_gmt":"2021-08-03T09:12:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=249"},"modified":"2021-08-03T09:12:00","modified_gmt":"2021-08-03T09:12:00","slug":"249","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/08\/03\/249\/","title":{"rendered":"Python\u811a\u672c: \u7edf\u8ba1\u8bbf\u95eeNginx\u7684\u524d100\u4e2aIP\u548c\u67e5\u8be2\u6240\u5728\u56fd\u5bb6\u548c\u57ce\u5e02"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/08\/2281641762.png\" alt=\"python\" title=\"python\"><\/p>\n<h3>\u811a\u672c <code>ipinfo.py<\/code> \u8bfb\u53d6 <code>iplist.txt<\/code> \u67e5\u8be2IP\u5730\u5740\u6240\u5728\u56fd\u5bb6\u548c\u57ce\u5e02<\/h3>\n<pre><code># ipinfo.py\nimport re\nimport ipdb\nimport ipaddress\n\ndb = ipdb.BaseStation(\"\/app\/qqwry.ipdb\")\n\nwith open(\"\/app\/iplist.txt\", \"r\") as f:\n    data = f.read()\n\niplist = re.findall(r\"\b(?:[0-9]{1,3}.){3}[0-9]{1,3}\b\", data)\nfor ip in iplist:\n   try:\n      ipaddress.ip_address(ip).is_global\n      print(ip, db.find(ip, \"CN\"))\n   except:\n      pass\n<\/code><\/pre>\n<h1>\u4f7f\u7528\u524d\u5148\u5b89\u88c5 ipip-ipdb \u5e93 \u548c QQ\u7eaf\u771fIP\u8868\u6570\u636e<\/h1>\n<p>wget <a href=\"https:\/\/cdn.jsdelivr.net\/npm\/qqwry.ipdb\/qqwry.ipdb\">https:\/\/cdn.jsdelivr.net\/npm\/qqwry.ipdb\/qqwry.ipdb<\/a><br \/>apt install python3-pip -y<br \/>pip3 install --upgrade pip requests<br \/>pip3 install ipip-ipdb<\/p>\n<h3>Shell \u547d\u4ee4\u67e5\u8be2 <code>nginx-php<\/code> \u5bb9\u5668\u65e5\u5fd7\uff0c\u83b7\u5f97 <code>iplist.txt<\/code> IP\u8868<\/h3>\n<pre><code>docker logs nginx-php \\r\n  | grep -oE '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}' | sort | uniq -c| sort -nrk 1 \\r\n  | head -n 100 &gt; iplist.txt\n\ndocker exec -it python3  python3 \/app\/ipinfo.py\n\n#   pip3 install beautifulsoup4  html5lib  ipip-ipdb<\/code><\/pre>\n<h3>\u9664\u4e86\u7edf\u8ba1\u7f51\u9875\u8bbf\u95ee\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528 <a href=\"https:\/\/lyvba.com\/wgmtu\">wgmtu<\/a> \u811a\u672c\u751f\u6210 <code>\/var\/log\/auth.log <\/code> \u7684IP\u8868<\/h3>\n<pre><code>bash wgmtu ip | tee iplist.txt\n\n# wgmtu \u811a\u672c\u5b9e\u9645\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\ncat \/var\/log\/auth.log \\r\n  | grep -oE '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}' | sort | uniq -c| sort -nrk 1<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u811a\u672c ipinfo.py \u8bfb\u53d6 iplist.txt \u67e5\u8be2IP\u5730\u5740\u6240\u5728\u56fd\u5bb6\u548c\u57ce\u5e02 # ipinfo. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[23,45],"class_list":["post-249","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux","tag-python"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=249"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/249\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}