Python multi-line Cheng script

Source: Internet
Author: User

requirements, there is an IP list file ip.txt, there are 1000 IP, then I will use Python to process the 1000 IP.
See Ip.txt first.
192.168.1.1
192.168.1.2
192.168.1.3
......
192.168.1.1000

multithreaded concurrency Scripts

#!/usr/bin/pythonimport threadingimport sysimport osimport timedef ssh_cmd (IP):        //define a Ssh_cmd function for 5 seconds in a daze, output IP        Time.sleep (5)        print ipdef ssh_cmd_spit (list):        //define a Ssh_cmd_spit function for performing the segmented IP list for        j in list:                j = J.strip ("\ n")                Ssh_cmd (j) def Thread_main (count):        //Defines a thread_main function that sets the number of IPs processed by each process, set to 1, Then 1000 IP needs to open 1000 threads at the same time, set to 50, then 20 threads need to be processed simultaneously.        file = open ("Ip.txt")        f = file.readlines ()        for I in range (0,len (f), int (count)):                B = f[i:i+count]< C14/>t = Threading. Thread (target=ssh_cmd_spit,args= (b,))   //Add thread                t.start ()        //processing thread if __name__ = = ' __main__ ':        Thread_main (1)


Python multi-line Cheng script

Related Article

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.