> On 27 Feb 2022, at 13:53, Byung-Hee HWANG <soyeo...@doraji.xyz> wrote:
>
> simple ping check script with python3 (Python 3.9.2)
> tested under Debian 11 Bullseye:
>
> soyeomul@penguin:~/gitlab/test$ ./fping.py localhost
> ok
> soyeomul@penguin:~/gitlab/test$ ./fping.py python.org
> ok
> soyeomul@penguin:~/gitlab/test$ ./fping.py python3.org
> python3.org: No address associated with hostname
> something is wrong...
This is correct python3.org <http://python3.org/> is only setup for email.
Use the host and dig commands to check for yourself.
Compare
$ host python.org <http://python.org/>
with
$ host python3.org
And compare:
$ dig -t A python.org <http://python.org/>
$ dig -t MX python.org <http://python.org/>
with
$ dig -t A python3.org <http://python.org/>
$ dig -t MX python3.org <http://python.org/>
Barry
> soyeomul@penguin:~/gitlab/test$
>
> Signed-off-by: Byung-Hee HWANG <soyeo...@doraji.xyz>
> ---
> fping.py | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
> create mode 100755 fping.py
>
> diff --git a/fping.py b/fping.py
> new file mode 100755
> index 0000000..ccc1e58
> --- /dev/null
> +++ b/fping.py
> @@ -0,0 +1,31 @@
> +#!/usr/bin/env python3
> +# -*- coding: utf-8 -*-
> +
> +from subprocess import PIPE, Popen
> +from os import path
> +import sys
> +
> +"""
> +REFERENCE:
> +<https://mail.python.org/pipermail/python-list/2022-February/thread.html#905156>
> +"""
> +
> +if not path.isfile('/usr/bin/fping'):
> + sys.exit("you first install fping, then try again...")
> +
> +def check(xyz):
> + cmd = "fping %s" % (xyz)
> + try_ = Popen(cmd, stdout=PIPE, shell=True)
> + output = try_.communicate()[0].decode("utf-8")
> +
> + return output
> +
> +
> +if __name__ == "__main__":
> + xyz = sys.argv[1]
> + if "alive" in check(xyz):
> + print("ok")
> + else:
> + print("something is wrong...")
> +
> +# 2022-02-27, GNU Emacs 27.1 (Debian 11 Bullseye)
> --
> 2.30.2
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
https://mail.python.org/mailman/listinfo/python-list