Python multi-thread port scanning code example, python multi-thread

Source: Internet
Author: User

Python multi-thread port scanning code example, python multi-thread

The code in this article implements multi-threaded port scanning in Python. The specific implementation code is as follows.

# Coding: utf-8import socketimport threadimport timesocket. setdefatimetimeout (3) def socket_port (ip, port): try: if port> = 65535: print (u "port Scan ends! ") S = socket. socket (socket. AF_INET, socket. SOCK_STREAM) # create socket result = s. connect_ex (ip, port) # link port if (result = 0): print ip, u ":", port, u "port Development" s. close () packet T: print (ip, ":", port) print (u "port Scan exception") def IP_port (data): try: ip = "127.0.0.1" t = time. time () for I in range (+ 1): thread. start_new_thread (socket_port, (ip, int (I) # multi-thread scan port time. sleep (0.003) print (u "when the scan port is completed: time _: % s" % (time. time ()-t) failed t Exception as e: print (e) print (ip, I) print (u "Port Scan Exception ") if _ name _ = '_ main _': print u "start to work" # socket_port ("127.0.0.1", 135) IP_port ("127.0.0.1 ")

The result is as follows:

Start work
127.0.0.1: port 135 Development
127.0.0.1: port 445 Development
Time _: 3.00300002098 when the scan port is completed
>>>

Summary

The above is all the content of this article on the Python multi-threaded port scanning code example, I hope to help you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

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.