The last script we need is a script that puts everything together and enables the logic of our application. This is going to be the Python script that we're going to execute in order to test and use the application. So looking at the code, we have about 30 lines of code that basically add up all the functionality inside the custom modules we've built thus far in this section. First of all, we have the import statements right here. And from each of the modules we have created, we are importing the function inside that module using the from import statement. We have five custom modules and all five of them are used inside the final application.
We are also importing the SIS module to quit the execution of the program in an elegant way using the exit method. Next, the first task is to have the list of IP addresses in the text file returned so that it will be usable in the namespace of this script. For this we are creating a variable called IP list that grabs the list returned by the IP file valid function inside the IP file valid dot p y module. Next, using a try except block in case we decide to prematurely end the program and hit Ctrl C, we handled the keyboard interrupt exception by printing out a message to the screen and exiting the application. The code under the try clause executes the IP addr valid function inside the module having the same name by passing the list of IP addresses as an argument. The same is done with the IP reach function right here.
These two pieces of code make sure that the IP addresses inside the list are valid and reachable, which is an essential step to perform before attempting the SSH connection. Finally, if no errors or issues or cure, the application invokes the Create threads function down here which further calls the SSH connection function and creates the threads. This way, an SSH connection is initiated to all the devices in the list simultaneously. Immediately after this video ends, you will be able to download the code for this final application, as well as all the necessary modules that we've built thus far, and that the application needs in order to perform its job. I advise you to create a new folder on your file system and store all of these Python scripts inside the same folder to avoid any issues related to locating each module. Moreover, you should also add the three text files holding the IP addresses login credentials and commands inside the same folder so that your work environment stays neat and organized.
Having that said I'll see you in the next lecture, where we're going to start testing our network application using the arrest of virtual machines. So see you soon