SSH-Config-Final - Application#2 Part#1 import paramiko...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
############# Application #2 - Part #1 ############# import paramiko import threading import os.path import subprocess import time import sys import re #Checking IP address file and content validity def ip_is_valid(): check = False global ip_list while True: #Prompting user for input print "\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\n" ip_file = raw_input("# Enter IP file name and extension: ") print "\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #" #Changing exception message try: #Open user selected file for reading (IP addresses file) selected_ip_file = open(ip_file, 'r') #Starting from the beginning of the file selected_ip_file.seek(0) #Reading each line (IP address) in the file ip_list = selected_ip_file.readlines() #Closing the file selected_ip_file.close() except IOError: print "\n* File %s does not exist! Please check and try again!\n" % ip_file #Checking octets for ip in ip_list: a = ip.split('.') if (len(a) == 4) and (1 <= int(a[0]) <= 223) and (int(a[0]) != 127) and (int(a[0]) != 169 or int(a[1]) != 254) and (0 <= int(a[1]) <= 255 and 0 <= int(a[2]) <= 255 and 0 <= int(a[3]) <= 255): check = True break else: print '\n* There was an INVALID IP address! Please check and try again!\n' check = False continue #Evaluating the 'check' flag if check == False: continue elif check == True: break ############# Application #2 - Part #2 #############
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
#Checking IP reachability print "\n* Checking IP reachability. Please wait...\n" check2 = False while True: for ip in ip_list: ping_reply = subprocess.call(['ping', '-c', '2', '-w', '2', '-q', '- n', ip]) if ping_reply == 0: check2 = True
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern