Coverage for mfutil/cli_tools/ping_tcp_port.py: 0%

21 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-13 15:33 +0000

1import argparse 

2import sys 

3from mfutil.net import ping_tcp_port 

4 

5DESCRIPTION = "test if a tcp host/port is reachable, open and listened" 

6 

7 

8def main(): 

9 parser = argparse.ArgumentParser(description=DESCRIPTION) 

10 parser.add_argument("host", help="hostname/ip to test") 

11 parser.add_argument("port", help="tcp port to test", type=int) 

12 parser.add_argument("--timeout", help="timeout (in seconds)", type=int, 

13 default=5) 

14 parser.add_argument("--silent", help="if set, nothing is sent on stdout", 

15 action="store_true") 

16 args = parser.parse_args() 

17 res = ping_tcp_port(args.host, args.port, timeout=args.timeout) 

18 if res: 

19 if not args.silent: 

20 print("tcp port %s:%i is ok" % (args.host, args.port)) 

21 sys.exit(0) 

22 if not args.silent: 

23 print("tcp port %s:%i is not ok" % (args.host, args.port)) 

24 sys.exit(1) 

25 

26 

27if __name__ == '__main__': 

28 main()