from icmplib import ping
hosts = ['family.cloudflare-dns.com', 'moodle.ncnu.edu.tw', 'sis.ncnu.edu.tw']
for host in hosts:
h = ping(host, privileged=False)
print(f"{host} ({h.address}) is", end='\t')
if h.is_alive:
print('alive')
else:
print('unreachable')
from icmplib import ping
hosts = ['family.cloudflare-dns.com', 'moodle.ncnu.edu.tw', 'sis.ncnu.edu.tw']
f = open('icmp.output', 'w')
for host in hosts:
h = ping(host, privileged=False)
print(f"{host} ({h.address}) is", end='\t', file=f)
if h.is_alive:
print('alive', file=f)
else:
print('unreachable', file=f)
f.close()
from datetime import datetime
now = datetime.now()
FN = '/home/solomon/SNMP/Code/icmp.' + now.strftime("icmp.%Y%m%d%H%M%S")
print(FN)
f = open('hosts.txt', 'r')
s = f.read()
print(s.upper(), end='')
f.close()
f = open('hosts.txt', 'r')
line = f.readline()
for c in line:
print(f"{c:>3}", end='')
for c in line:
print(f"{ord(c):3}", end='')
print()
f.close()
f = open('hosts.txt', 'r')
lines = f.readlines()
f.close()
for i in range(len(lines)):
print(i, lines[i][:-1])
f = open('hosts.txt', 'r')
n = 0
for line in f:
print(n, line[:-1])
n += 1
f.close()