ping script
Byung-Hee HWANG
soyeomul at doraji.xyz
Sun Feb 27 08:53:27 EST 2022
simple ping check script with python3 (Python 3.9.2)
tested under Debian 11 Bullseye:
soyeomul at penguin:~/gitlab/test$ ./fping.py localhost
ok
soyeomul at penguin:~/gitlab/test$ ./fping.py python.org
ok
soyeomul at penguin:~/gitlab/test$ ./fping.py python3.org
python3.org: No address associated with hostname
something is wrong...
soyeomul at penguin:~/gitlab/test$
Signed-off-by: Byung-Hee HWANG <soyeomul at 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
More information about the Python-list
mailing list