ReadIPs #1
30
status.py
30
status.py
@@ -18,9 +18,7 @@ def parseArguments():
|
||||
try:
|
||||
# Parsear los argumentos de la línea de comandos
|
||||
args = parser.parse_args()
|
||||
if args.web and args.host:
|
||||
return args.host, args.web
|
||||
elif args.host:
|
||||
if args.host:
|
||||
return args.host
|
||||
elif args.web:
|
||||
return args.web
|
||||
@@ -31,14 +29,32 @@ def parseArguments():
|
||||
parser.print_help()
|
||||
exit()
|
||||
|
||||
def check_ping(host):
|
||||
def toIP(hosts):
|
||||
ips = set()
|
||||
for host in hosts:
|
||||
try:
|
||||
response = ping(host, count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
||||
return True if response.success() else False
|
||||
ip = ipaddress.IPv4Address(host)
|
||||
ips.add(ip)
|
||||
except ipaddress.AddressValueError:
|
||||
print(f"La entrada '{ip}' no es una dirección IP válida.")
|
||||
return ips
|
||||
|
||||
def check_ping(hosts):
|
||||
for host in hosts:
|
||||
try:
|
||||
print(f'Pingin host: {host}')
|
||||
response = ping(str(host), count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
||||
if not response.success():
|
||||
print(False)
|
||||
# Ennviar un mensaje
|
||||
else:
|
||||
print(True)
|
||||
except Exception as e:
|
||||
print(f"Error making ping to {host}: {e}")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parseArguments()
|
||||
hosts = read_document(args)
|
||||
ips = toIP(hosts)
|
||||
check_ping(ips)
|
||||
Reference in New Issue
Block a user