ReadIPs #1
36
status.py
36
status.py
@@ -18,9 +18,7 @@ def parseArguments():
|
|||||||
try:
|
try:
|
||||||
# Parsear los argumentos de la línea de comandos
|
# Parsear los argumentos de la línea de comandos
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.web and args.host:
|
if args.host:
|
||||||
return args.host, args.web
|
|
||||||
elif args.host:
|
|
||||||
return args.host
|
return args.host
|
||||||
elif args.web:
|
elif args.web:
|
||||||
return args.web
|
return args.web
|
||||||
@@ -31,14 +29,32 @@ def parseArguments():
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def check_ping(host):
|
def toIP(hosts):
|
||||||
try:
|
ips = set()
|
||||||
response = ping(host, count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
for host in hosts:
|
||||||
return True if response.success() else False
|
try:
|
||||||
except Exception as e:
|
ip = ipaddress.IPv4Address(host)
|
||||||
print(f"Error making ping to {host}: {e}")
|
ips.add(ip)
|
||||||
return False
|
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}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parseArguments()
|
args = parseArguments()
|
||||||
|
hosts = read_document(args)
|
||||||
|
ips = toIP(hosts)
|
||||||
|
check_ping(ips)
|
||||||
Reference in New Issue
Block a user