{"id":230,"date":"2017-12-08T02:13:55","date_gmt":"2017-12-08T02:13:55","guid":{"rendered":""},"modified":"2017-12-08T02:13:55","modified_gmt":"2017-12-08T02:13:55","slug":"","status":"publish","type":"post","link":"http:\/\/weizn.net\/?p=230","title":{"rendered":"Python\u4e2d\u5173\u4e8eIP\u5904\u7406\u7684\u4e24\u4e2a\u6a21\u5757"},"content":{"rendered":"<p style=\"margin-top:0px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">\u8fd9\u91cc\u4ecb\u7ecd\u7684\u4e24\u4e2a\u5904\u7406IP\u597d\u7528\u7684Python\u5e93\u540d\u4e3a\uff1aipaddr\u548cnetaddr<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">\u987a\u4fbf\u63d0\u4e00\u4e2a\u4e0d\u597d\u7528\u7684\uff1aIPy\u3002\u4e0a\u9762\u4e24\u4e2a\u80fd\u5b8c\u5168\u80dc\u4efb\u8fd9\u4e2a\u5e93\u7684\u529f\u80fd\uff0c\u4f46\u8fd9\u4e2a\u5e93\u5bb9\u9519\u6027\u4e0d\u597d\uff0c\u5e38\u62a5\u9519\u3002<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\"><strong>1.ipaddr\u7b80\u5355\u4ecb\u7ecd\uff1a<\/strong><\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">Google\u5f00\u53d1\u7684IP\u5904\u7406\u6a21\u5757\uff0c\u5730\u5740\uff1a<\/span><a class=\"external-link\" href=\"http:\/\/pythonhosted.org\/ipaddr\/\" rel=\"nofollow\"><span style=\"font-size:16px;line-height:1;\">http:\/\/pythonhosted.org\/ipaddr\/<\/span><\/a>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">\u53ef\u7528pip\u5b89\u88c5\uff1apip install ipaddr<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">\u6240\u6709\u5305\u542b\u7684\u7c7b\u548c\u65b9\u6cd5\u4f7f\u7528help\u547d\u4ee4\u67e5\u770b\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">help(ipaddr)<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:14px;\"><br \/>\n<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">Class\u603b\u5171\u5206\u4e3a\uff1aBaseIP\u3001IPv4\u3001IPv6<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> ipaddr.IPv4Network() ipv4\u7f51\u6bb5\u5bf9\u8c61\u5efa\u7acb<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> ipaddr.IPv6Network() ipv6\u7f51\u6bb5\u5bf9\u8c61\u5efa\u7acb<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> ipaddr.IPAddress(address, version) \u5355\u4e2aipv4\u5730\u5740\u5bf9\u8c61\u5efa\u7acb<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:14px;\"><span style=\"line-height:1;font-size:16px;\"><\/span><br \/>\n<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">DEMO:<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">1\uff09\u5224\u65ad\u4e00\u4e2aIP\u5730\u5740\u662f\u5426\u5728\u67d0\u4e2a\u7f51\u6bb5\u5185\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; import ipaddr<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt;&nbsp;<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; ip = ipaddr.IPv4Address(&#8220;192.168.1.1&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; ipNet = ipaddr.IPv4Network(&#8220;192.168.1.0\/23&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; print ip in ipNet<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> True<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">\u8fd4\u56deTrue\u6ca1\u95ee\u9898\uff0c\u82e5\u4e0d\u5c5e\u4e8e\u5305\u542b\u5173\u7cfb\u8fd4\u56deFalse<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">2\uff09\u5224\u65ad\u4e00\u4e2a\u7f51\u6bb5\u662f\u5426\u5c5e\u4e8e\u53e6\u4e00\u4e2a\u7f51\u6bb5\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; ipNetA = ipaddr.IPv4Network(&#8220;192.168.1.0\/24&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; ipNetB = ipaddr.IPv4Network(&#8220;192.168.0.0\/16&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; print ipNetA in ipNetB<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> True<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">3\uff09\u5224\u65ad\u662f\u5426\u5c5e\u4e8e\u5185\u7f51IP\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; ip = ipaddr.IPv4Address(&#8220;1.1.1.1&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; print ip.is_private<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> False<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> 4\uff09\u5224\u65ad\u662f\u5426\u5c5e\u4e8e\u5185\u7f51\u7f51\u6bb5\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; ipNet = ipaddr.IPv4Network(&#8220;10.123.1.0\/24&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; print ipNet.is_private<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> True<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">5\uff09\u8fd4\u56de\u5b50\u7f51\u4e2dIP\u4e2a\u6570\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; ipNet = ipaddr.IPv4Network(&#8220;192.168.0.0\/16&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; print ipNet.numhosts<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> 65536<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">6\uff09\u904d\u5386\u7f51\u6bb5\u4e2d\u6240\u6709IP\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; ipNet = ipaddr.IPv4Network(&#8220;192.168.0.1\/32&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; for ip in ipNet:<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print isinstance(ip, ipaddr.IPv4Address)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print str(ip)<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">True<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> 192.168.0.1<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">\u6ce8\u610f\uff0c\u8fd9\u91cc\u904d\u5386\u65f6\u8fd4\u56de\u7684\u5143\u7d20\u662fipaddr.IPv4Address\u5bf9\u8c61\uff0c\u4e0d\u662f\u4e00\u4e2aIP\u5b57\u7b26\u4e32\uff0c\u4f46\u53ef\u4ee5\u8f6c\u6362\u3002<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">7\uff09\u6839\u636e\u7d22\u5f15\u8bbf\u95ee\u7f51\u6bb5\u4e2d\u7684\u67d0\u4e2aIP\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; ipNet = ipaddr.IPv4Network(&#8220;192.168.0.0\/24&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; print str(ipNet[3])<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> 192.168.0.3<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\"><strong>2.netaddr\u4ecb\u7ecd<\/strong><\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">\u4e5f\u4f7f\u7528pip\u5b89\u88c5\uff1apip install netaddr<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">help\u547d\u4ee4\u67e5\u770b\u6240\u6709\u7c7b\u548c\u65b9\u6cd5\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">help(netaddr)<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">\u6587\u6863\u5730\u5740\uff1a<\/span><a class=\"external-link\" href=\"https:\/\/netaddr.readthedocs.io\/en\/latest\/\" rel=\"nofollow\"><span style=\"font-size:16px;line-height:1;\">https:\/\/netaddr.readthedocs.io\/en\/latest\/<\/span><\/a>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">DEMO:<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">1\uff09\u63a9\u7801\u8f6c\u6362\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; import netaddr<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt;&nbsp;<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; ipNetList = netaddr.iprange_to_cidrs(&#8220;192.168.1.1&#8221;, &#8220;192.168.1.100&#8221;)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; print ipNetList<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> [IPNetwork(&#8216;192.168.1.1\/32&#8217;), IPNetwork(&#8216;192.168.1.2\/31&#8217;), IPNetwork(&#8216;192.168.1.4\/30&#8217;), IPNetwork(&#8216;192.168.1.8\/29&#8217;), IPNetwork(&#8216;192.168.1.16\/28&#8217;), IPNetwork(&#8216;192.168.1.32\/27&#8217;), IPNetwork(&#8216;192.168.1.64\/27&#8217;), IPNetwork(&#8216;192.168.1.96\/30&#8217;), IPNetwork(&#8216;192.168.1.100\/32&#8217;)]<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">2\uff09\u5408\u5e76IP\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; ipList = [netaddr.IPAddress(&#8220;1.1.1.1&#8221;), netaddr.IPAddress(&#8220;1.1.1.2&#8221;)]<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; print netaddr.cidr_merge(ipList)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> [IPNetwork(&#8216;1.1.1.1\/32&#8217;), IPNetwork(&#8216;1.1.1.2\/32&#8217;)]<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">3\uff09\u5f53\u7136\u4e5f\u53ef\u4ee5\u5408\u5e76\u7f51\u6bb5\uff1a<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">&gt;&gt;&gt; ipList = [netaddr.IPNetwork(&#8220;1.1.3.0\/23&#8221;), netaddr.IPNetwork(&#8220;1.1.0.0\/22&#8221;)]<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> &gt;&gt;&gt; print netaddr.cidr_merge(ipList)<\/span><br \/>\n<span style=\"font-size:16px;line-height:1;\"> [IPNetwork(&#8216;1.1.0.0\/22&#8217;)]<\/span>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;white-space:normal;\">\n\t<span style=\"font-size:16px;line-height:1;\">\u7f51\u6bb5\u548c\u5355\u4e2aIP\u6df7\u5408\u5408\u5e76\u4e5f\u53ef\u4ee5\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p style=\"margin-top:0px;margin-bottom:0px;padding:0px;color:#333333;font-family:Arial, sans-serif;font-size:14px;white-space:normal;background-color:#FFFFFF;\">\n\t\u8fd9\u91cc\u4ecb\u7ecd\u7684\u4e24\u4e2a\u5904\u7406IP\u597d\u7528\u7684Python\u5e93\u540d\u4e3a\uff1aipaddr\u548cnetaddr\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;color:#333333;font-family:Arial, sans-serif;font-size:14px;white-space:normal;background-color:#FFFFFF;\">\n\t\u987a\u4fbf\u63d0\u4e00\u4e2a\u4e0d\u597d\u7528\u7684\uff1aIPy\u3002\u4e0a\u9762\u4e24\u4e2a\u80fd\u5b8c\u5168\u80dc\u4efb\u8fd9\u4e2a\u5e93\u7684\u529f\u80fd\uff0c\u4f46\u8fd9\u4e2a\u5e93\u5bb9\u9519\u6027\u4e0d\u597d\uff0c\u5e38\u62a5\u9519\u3002\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;color:#333333;font-family:Arial, sans-serif;font-size:14px;white-space:normal;background-color:#FFFFFF;\">\n\t<strong>1.ipaddr\u7b80\u5355\u4ecb\u7ecd\uff1a<\/strong>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;color:#333333;font-family:Arial, sans-serif;font-size:14px;white-space:normal;background-color:#FFFFFF;\">\n\tGoogle\u5f00\u53d1\u7684IP\u5904\u7406\u6a21\u5757\uff0c\u5730\u5740\uff1a<a class=\"external-link\" href=\"http:\/\/pythonhosted.org\/ipaddr\/\" rel=\"nofollow\" style=\"color:#3572B0;text-decoration:none;\">http:\/\/pythonhosted.org\/ipaddr\/<\/a>\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;color:#333333;font-family:Arial, sans-serif;font-size:14px;white-space:normal;background-color:#FFFFFF;\">\n\t\u53ef\u7528pip\u5b89\u88c5\uff1apip install ipaddr\n<\/p>\n<p style=\"margin-top:10px;margin-bottom:0px;padding:0px;color:#333333;font-family:Arial, sans-serif;font-size:14px;white-space:normal;background-color:#FFFFFF;\">\n\t\u6240\u6709\u5305\u542b\u7684\u7c7b\u548c\u65b9&#8230;<\/p>\n","protected":false},"author":1,"featured_media":559,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[334],"tags":[],"class_list":["post-230","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u4e2d\u5173\u4e8eIP\u5904\u7406\u7684\u4e24\u4e2a\u6a21\u5757 - Wayne&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/weizn.net\/?p=230\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u4e2d\u5173\u4e8eIP\u5904\u7406\u7684\u4e24\u4e2a\u6a21\u5757 - Wayne&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"\u8fd9\u91cc\u4ecb\u7ecd\u7684\u4e24\u4e2a\u5904\u7406IP\u597d\u7528\u7684Python\u5e93\u540d\u4e3a\uff1aipaddr\u548cnetaddr  \u987a\u4fbf\u63d0\u4e00\u4e2a\u4e0d\u597d\u7528\u7684\uff1aIPy\u3002\u4e0a\u9762\u4e24\u4e2a\u80fd\u5b8c\u5168\u80dc\u4efb\u8fd9\u4e2a\u5e93\u7684\u529f\u80fd\uff0c\u4f46\u8fd9\u4e2a\u5e93\u5bb9\u9519\u6027\u4e0d\u597d\uff0c\u5e38\u62a5\u9519\u3002  1.ipaddr\u7b80\u5355\u4ecb\u7ecd\uff1a  Google\u5f00\u53d1\u7684IP\u5904\u7406\u6a21\u5757\uff0c\u5730\u5740\uff1ahttp:\/\/pythonhosted.org\/ipaddr\/  \u53ef\u7528pip\u5b89\u88c5\uff1apip install ipaddr  \u6240\u6709\u5305\u542b\u7684\u7c7b\u548c\u65b9...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/weizn.net\/?p=230\" \/>\n<meta property=\"og:site_name\" content=\"Wayne&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-08T02:13:55+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"zinan\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/weizn.net\/#website\",\"url\":\"http:\/\/weizn.net\/\",\"name\":\"Wayne&#039;s Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/weizn.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/weizn.net\/?p=230#primaryimage\",\"inLanguage\":\"zh-Hans\",\"url\":\"http:\/\/weizn.net\/wp-content\/uploads\/2019\/01\/timg.jpg\",\"contentUrl\":\"http:\/\/weizn.net\/wp-content\/uploads\/2019\/01\/timg.jpg\",\"width\":1395,\"height\":864},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/weizn.net\/?p=230#webpage\",\"url\":\"http:\/\/weizn.net\/?p=230\",\"name\":\"Python\\u4e2d\\u5173\\u4e8eIP\\u5904\\u7406\\u7684\\u4e24\\u4e2a\\u6a21\\u5757 - Wayne&#039;s Blog\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/weizn.net\/?p=230#primaryimage\"},\"datePublished\":\"2017-12-08T02:13:55+00:00\",\"dateModified\":\"2017-12-08T02:13:55+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/weizn.net\/?p=230#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/weizn.net\/?p=230\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/weizn.net\/?p=230#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\\u9996\\u9875\",\"item\":\"http:\/\/weizn.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\\u4e2d\\u5173\\u4e8eIP\\u5904\\u7406\\u7684\\u4e24\\u4e2a\\u6a21\\u5757\"}]},{\"@type\":\"Article\",\"@id\":\"http:\/\/weizn.net\/?p=230#article\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/?p=230#webpage\"},\"author\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"headline\":\"Python\\u4e2d\\u5173\\u4e8eIP\\u5904\\u7406\\u7684\\u4e24\\u4e2a\\u6a21\\u5757\",\"datePublished\":\"2017-12-08T02:13:55+00:00\",\"dateModified\":\"2017-12-08T02:13:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/weizn.net\/?p=230#webpage\"},\"wordCount\":302,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"image\":{\"@id\":\"http:\/\/weizn.net\/?p=230#primaryimage\"},\"thumbnailUrl\":\"http:\/\/weizn.net\/wp-content\/uploads\/2019\/01\/timg.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/weizn.net\/?p=230#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\",\"name\":\"zinan\",\"logo\":{\"@id\":\"http:\/\/weizn.net\/#personlogo\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python\u4e2d\u5173\u4e8eIP\u5904\u7406\u7684\u4e24\u4e2a\u6a21\u5757 - Wayne&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/weizn.net\/?p=230","og_locale":"zh_CN","og_type":"article","og_title":"Python\u4e2d\u5173\u4e8eIP\u5904\u7406\u7684\u4e24\u4e2a\u6a21\u5757 - Wayne&#039;s Blog","og_description":"\u8fd9\u91cc\u4ecb\u7ecd\u7684\u4e24\u4e2a\u5904\u7406IP\u597d\u7528\u7684Python\u5e93\u540d\u4e3a\uff1aipaddr\u548cnetaddr  \u987a\u4fbf\u63d0\u4e00\u4e2a\u4e0d\u597d\u7528\u7684\uff1aIPy\u3002\u4e0a\u9762\u4e24\u4e2a\u80fd\u5b8c\u5168\u80dc\u4efb\u8fd9\u4e2a\u5e93\u7684\u529f\u80fd\uff0c\u4f46\u8fd9\u4e2a\u5e93\u5bb9\u9519\u6027\u4e0d\u597d\uff0c\u5e38\u62a5\u9519\u3002  1.ipaddr\u7b80\u5355\u4ecb\u7ecd\uff1a  Google\u5f00\u53d1\u7684IP\u5904\u7406\u6a21\u5757\uff0c\u5730\u5740\uff1ahttp:\/\/pythonhosted.org\/ipaddr\/  \u53ef\u7528pip\u5b89\u88c5\uff1apip install ipaddr  \u6240\u6709\u5305\u542b\u7684\u7c7b\u548c\u65b9...","og_url":"http:\/\/weizn.net\/?p=230","og_site_name":"Wayne&#039;s Blog","article_published_time":"2017-12-08T02:13:55+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"zinan","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/weizn.net\/#website","url":"http:\/\/weizn.net\/","name":"Wayne&#039;s Blog","description":"","publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/weizn.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"ImageObject","@id":"http:\/\/weizn.net\/?p=230#primaryimage","inLanguage":"zh-Hans","url":"http:\/\/weizn.net\/wp-content\/uploads\/2019\/01\/timg.jpg","contentUrl":"http:\/\/weizn.net\/wp-content\/uploads\/2019\/01\/timg.jpg","width":1395,"height":864},{"@type":"WebPage","@id":"http:\/\/weizn.net\/?p=230#webpage","url":"http:\/\/weizn.net\/?p=230","name":"Python\u4e2d\u5173\u4e8eIP\u5904\u7406\u7684\u4e24\u4e2a\u6a21\u5757 - Wayne&#039;s Blog","isPartOf":{"@id":"http:\/\/weizn.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/weizn.net\/?p=230#primaryimage"},"datePublished":"2017-12-08T02:13:55+00:00","dateModified":"2017-12-08T02:13:55+00:00","breadcrumb":{"@id":"http:\/\/weizn.net\/?p=230#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/weizn.net\/?p=230"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/weizn.net\/?p=230#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/weizn.net\/"},{"@type":"ListItem","position":2,"name":"Python\u4e2d\u5173\u4e8eIP\u5904\u7406\u7684\u4e24\u4e2a\u6a21\u5757"}]},{"@type":"Article","@id":"http:\/\/weizn.net\/?p=230#article","isPartOf":{"@id":"http:\/\/weizn.net\/?p=230#webpage"},"author":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"headline":"Python\u4e2d\u5173\u4e8eIP\u5904\u7406\u7684\u4e24\u4e2a\u6a21\u5757","datePublished":"2017-12-08T02:13:55+00:00","dateModified":"2017-12-08T02:13:55+00:00","mainEntityOfPage":{"@id":"http:\/\/weizn.net\/?p=230#webpage"},"wordCount":302,"commentCount":0,"publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"image":{"@id":"http:\/\/weizn.net\/?p=230#primaryimage"},"thumbnailUrl":"http:\/\/weizn.net\/wp-content\/uploads\/2019\/01\/timg.jpg","articleSection":["Python"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/weizn.net\/?p=230#respond"]}]},{"@type":["Person","Organization"],"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264","name":"zinan","logo":{"@id":"http:\/\/weizn.net\/#personlogo"}}]}},"_links":{"self":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230"}],"version-history":[{"count":0,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/media\/559"}],"wp:attachment":[{"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}