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