Python daily Exercise 20170611

Source: Internet
Author: User

#!/usr/local/bin/python#-*- coding: utf-8 -*-#端口扫描器import  socketimport threadimport  timesocket.setdefaulttimeout (3)    #设置了全局默认超时时间def  socket_port (ip,port):   #扫描开放端口     try:        if PORT>=65535:             print u "Port scan end 0-65535"          s = socket.socket (Socket.af_inet, socket. SOCK_STREAM)          #s. settimeout (float (1))    #延时5S           #s. Connect ((ip,port))          RESULT=S.CONNECT_EX ((Ip,port))         if (result==0):             print ip,u ":", PORT,u "Port open"          s.close ()      except:        print u "Scan Port exception 2" Def IP__port ( Data):  #扫描端口     try:         #data = "127.0.0.1"         t=time.time ()          For i in range (0,1000 + 1):    #65535              thread.start_new_thread (Socket_port, (Data,int (i)))              time.sleep (0.003)   #确保先运行Seeker中的方法          print u ' Scan port complete  time:%f '  %  (Time.time ()-T)      except:        print u "Scan Port exception 1" if __name__ = = ' __main__ ':     #socket_port ("127.0.0.1")    #扫描开放端口     ip __port ("127.0.0.1")   #多线Ride 


Python daily Exercise 20170611

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.