import paramiko
import time

reachable_ip = []
unreachable_ip = []

def ping_device(host,password):

    ssh_client = paramiko.SSHClient()
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_client.connect(hostname='10.0.12.1', username='advait', password=password)
    remote_connection = ssh_client.invoke_shell()
    cmd = 'ping ' + host + ' timeout 1 \n'
    remote_connection.send(cmd)
    time.sleep(2)
    output = remote_connection.recv(65536)
    output = output.decode()
    temp_lst = output.split(':')
    temp_lst2 = temp_lst[1].split('\n')
    if temp_lst2[1].strip() == '.':
        time.sleep(5)
        unreachable_ip.append(host)
    elif temp_lst2[1].strip() == '!!!!!':
        reachable_ip.append(host)

f = open('ip.txt', 'r')
ip_list = []
for i in f:
    ip_list.append(i.strip())

start = time.time()

for ip in ip_list:
    ping_device(ip, ‘cisco’)

end = time.time()

print 'total time: ' + str(end-start)
print 'reachable ip address list: '
print reachable_ip
print 'unreachable ip address list: '
print unreachable_ip
0e405ac1a08bce127de24164c287383ff4aa7f7b
import paramiko
import time

reachable_ip = []
unreachable_ip = []

def ping_device(host,password):

    ssh_client = paramiko.SSHClient()
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_client.connect(hostname='10.0.12.1', username='advait', password=password)
    remote_connection = ssh_client.invoke_shell()
    cmd = 'ping ' + host + ' timeout 1 \n'
    remote_connection.send(cmd)
    time.sleep(2)
    output = remote_connection.recv(65536)
    output = output.decode()
    temp_lst = output.split(':')
    temp_lst2 = temp_lst[1].split('\n')
    if temp_lst2[1].strip() == '.':
        time.sleep(5)
        unreachable_ip.append(host)
    elif temp_lst2[1].strip() == '!!!!!':
        reachable_ip.append(host)

f = open('ip.txt', 'r')
ip_list = []
for i in f:
    ip_list.append(i.strip())

start = time.time()

for ip in ip_list:
    ping_device(ip, ‘cisco’)

end = time.time()

print 'total time: ' + str(end-start)
print 'reachable ip address list: '
print reachable_ip
print 'unreachable ip address list: '
print unreachable_ip