{"id":354,"date":"2014-07-03T10:48:31","date_gmt":"2014-07-03T10:48:31","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=354"},"modified":"2014-07-03T10:48:31","modified_gmt":"2014-07-03T10:48:31","slug":"%e7%ab%af%e5%8f%a3%e6%89%ab%e6%8f%8f%e7%9a%84python%e8%84%9a%e6%9c%acbak","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/354.html","title":{"rendered":"\u7aef\u53e3\u626b\u63cf\u7684Python\u811a\u672c[bak]"},"content":{"rendered":"<p>\u627e\u5230\u4e86\u4e00\u4e2a\u7aef\u53e3\u626b\u63cf\u7684Python\u5c0f\u811a\u672c\uff0c\u505a\u4e2a\u5907\u4efd&amp;\u5b66\u4e60\uff1a<\/p>\n<pre class=\"lang:python decode:true\">#!\/usr\/bin\/env python\n# -*- coding: utf-8 -*-\n\nimport time, socket, thread\n\nsocket.setdefaulttimeout(3)\n\ndef port_scan(ip, port):\n    try:\n        if port&gt;=65535:\n            print 'Scanning port's range is 0-65535'\n            port = 5000\n        # create an AF_INET, STREAM socket (TCP)\n        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n        scan_result = s.connect_ex((ip, port))\n        if scan_result == 0:\n            print ip, \":\", port, \"Port is open!\"\n        s.close()\n    except:\n        print \"port-scan error-1\"\n\ndef ip_scan(ipaddress):\n    try:\n        t = time.time()\n        for item in range(0, 1000+1):\n            #\u4f7f\u7528start_new_thread\u51fd\u6570\u53ef\u4ee5\u7b80\u5355\u7684\u542f\u52a8\u4e00\u4e2a\u7ebf\u7a0b\n            #\u7b2c\u4e00\u4e2a\u53c2\u6570\u6307\u5b9a\u7ebf\u7a0b\u4e2d\u6267\u884c\u7684\u51fd\u6570\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u5143\u7ec4\u578b\u7684\u4f20\u9012\u7ed9\u6307\u5b9a\u51fd\u6570\u7684\u53c2\u6570\u503c\n            thread.start_new_thread(port_scan, (ipaddress, int(item)))\n            time.sleep(0.003)\n        print 'Port-scan complete! Takes: %f seconds.'% (time.time()-t)\n    except:\n        print \"port-scan error-2\"\n\nif __name__ == \"__main__\":\n\tip_scan(\"127.0.0.1\")\n\tip_scan(\"192.168.1.1\")<\/pre>\n<p>\u4ee3\u7801\u77ed\u5c0f\u7cbe\u608d\uff0c\u7528\u7684\u662f\u5e95\u5c42\u7684socket\u52a0\u4e0a\u591a\u7ebf\u7a0b\uff0c\u901f\u5ea6\u8fd8\u662f\u5f88\u5feb\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u627e\u5230\u4e86\u4e00\u4e2a\u7aef\u53e3\u626b\u63cf\u7684Python\u5c0f\u811a\u672c\uff0c\u505a\u4e2a\u5907\u4efd&amp;\u5b66\u4e60\uff1a #!\/usr\/bin\/env python  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,25,12],"tags":[8,173,124],"class_list":["post-354","post","type-post","status-publish","format-standard","hentry","category-programing","category-security","category-tools","tag-python","tag-socket","tag-thread"],"views":3743,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=354"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/354\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}