Compare commits
2 Commits
eceb7ad1f3
...
03dd3ba495
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03dd3ba495 | ||
|
|
fc40664ddf |
27
status.py
27
status.py
@@ -1,22 +1,29 @@
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
def parseArguments():
|
||||
# Crear un objeto ArgumentParser
|
||||
parser = argparse.ArgumentParser(description='Ejemplo de script con flags')
|
||||
|
||||
# Agregar los argumentos con sus respectivos flags
|
||||
parser.add_argument('-w', '--web', action='store', dest='web', help='Indicar una web')
|
||||
parser.add_argument('-h', '--host', action='store', dest='host', help='Indicar un host')
|
||||
parser.add_argument('-W', '--web', action='store', dest='web', help='Indicar un archivo con lista de Webs')
|
||||
parser.add_argument('-H', '--host', action='store', dest='host', help='Indicar un archivo con lista de hosts')
|
||||
|
||||
# Parsear los argumentos de la línea de comandos
|
||||
args = parser.parse_args()
|
||||
|
||||
return args
|
||||
try:
|
||||
# Parsear los argumentos de la línea de comandos
|
||||
args = parser.parse_args()
|
||||
if args.web:
|
||||
return args.web
|
||||
elif args.host:
|
||||
return args.host
|
||||
except argparse.ArgumentError as e:
|
||||
# Si ocurre un error al analizar los argumentos, mostrar un mensaje de error
|
||||
print("Error:", e)
|
||||
# Mostrar el mensaje de ayuda
|
||||
parser.print_help()
|
||||
exit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parseArguments()
|
||||
if args.web:
|
||||
print()# Parte web, comprobar que Código devuelve
|
||||
else:
|
||||
print()# Parte host, hará ping
|
||||
print(args)
|
||||
Reference in New Issue
Block a user