libf 2 年之前
父节点
当前提交
2f5cdb6744
共有 1 个文件被更改,包括 21 次插入0 次删除
  1. 21 0
      ping_telnet/tel.sh

+ 21 - 0
ping_telnet/tel.sh

@@ -0,0 +1,21 @@
+
+export ip=$1
+export port=$2
+export tmout=$3
+
+if [[ "$ip" == "" ]]; then
+  echo "usage: "$0" <ip> [port=80] [timeout=1]"
+  exit 1
+fi
+if [[ "$port" == "" ]]; then
+  export port=80
+fi
+if [[ "$tmout" == "" ]]; then
+  export tmout=1
+fi
+
+python -c 'import socket
+sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+sock.settimeout('$tmout')
+print("ok" if sock.connect_ex(("'$ip'", '$port')) == 0 else "timeout")
+'