From b04059e6da7ff36adecc91bde182465e5f0bcb1c Mon Sep 17 00:00:00 2001 From: axiaxixixixi <306232627@qq.com> Date: Fri, 9 Aug 2024 16:31:33 +0800 Subject: [PATCH] =?UTF-8?q?gs=5Fcheck=20-i=20CheckNetSpeed=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspection/items/network/CheckNetSpeed.py | 15 ++++++++---- .../inspection/lib/checknetspeed/speed_test | 23 +++++++++++++++---- script/local/KerberosUtility.py | 2 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/script/gspylib/inspection/items/network/CheckNetSpeed.py b/script/gspylib/inspection/items/network/CheckNetSpeed.py index 7a02392..619169c 100644 --- a/script/gspylib/inspection/items/network/CheckNetSpeed.py +++ b/script/gspylib/inspection/items/network/CheckNetSpeed.py @@ -28,6 +28,8 @@ from gspylib.inspection.common.CheckResult import ResultStatus from gspylib.common.ErrorCode import ErrorCode from base_utils.os.net_util import NetUtil +PING_CMD_IPV4 = "ping" +PING_CMD_IPV6 = "ping6" DEFAULT_PARALLEL_NUM = 12 DEFAULT_LISTEN_PORT = 20000 DEFINE_DELAY_WARNING = 1000 @@ -108,8 +110,13 @@ class CheckNetSpeed(BaseItem): global MaxDelayFailFlag global errorMsg global serviceIP - cmd = "ping -s 8192 -c 10 -i 0.3 %s|awk -F / '{print $7}'|" \ - "awk '{print $1}'" % ip + global pingCmd + if NetUtil.get_ip_version(ip) == NetUtil.NET_IPV6: + pingCmd = PING_CMD_IPV6 + else: + pingCmd = PING_CMD_IPV4 + cmd = "%s -s 8192 -c 10 -i 0.3 %s|awk -F / '{print $7}'|" \ + "awk '{print $1}'" % (pingCmd, ip) output = SharedFuncs.runShellCmd(cmd) if (output.strip() != ""): try: @@ -122,8 +129,8 @@ class CheckNetSpeed(BaseItem): return if (max_delay > DEFINE_DELAY_WARNING): g_lock.acquire() - string = "%s ping %s max delay is %.3fms" % ( - serviceIP, ip, max_delay) + string = "%s %s %s max delay is %.3fms" % ( + serviceIP, pingCmd, ip, max_delay) errorMsg.append(string) g_lock.release() diff --git a/script/gspylib/inspection/lib/checknetspeed/speed_test b/script/gspylib/inspection/lib/checknetspeed/speed_test index 97e1c70..36e2886 100644 --- a/script/gspylib/inspection/lib/checknetspeed/speed_test +++ b/script/gspylib/inspection/lib/checknetspeed/speed_test @@ -19,19 +19,32 @@ import socket import time import sys - -from base_utils.os.net_util import NetUtil +import ipaddress listen_ip = "localhost" listen_port = 31111 run_mode = 0 # 0:connect, 1:send, 2:recv +NET_IPV4 = "ipv4" +NET_IPV6 = "ipv6" + +def get_sockects(ip_address): + try: + ip = ipaddress.ip_address(ip_address) + if ip.version == 6: + sockets = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + return sockets + else: + sockets = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + return sockets + except ValueError: + print("ip_address:%s is unvalid ip.") def send_main(): try: global listen_ip global listen_port buf = "this is a test !" * 512 # buf 8192 block - sockets = NetUtil.get_sockects(listen_ip) + sockets = get_sockects(listen_ip) sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) print(listen_ip+":"+listen_port) while(sockets.connect_ex((listen_ip, int(listen_port))) != 0): @@ -54,7 +67,7 @@ def recv_main(): try: global listen_ip global listen_port - sockets = NetUtil.get_sockects(listen_ip) + sockets = get_sockects(listen_ip) sockets.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sockets.bind((listen_ip, int(listen_port))) @@ -72,7 +85,7 @@ def recv_main(): except Exception as e: print(str(e)) def connect_main(): - sockets = NetUtil.get_sockects(listen_ip) + sockets = get_sockects(listen_ip) sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) if sockets.connect_ex((listen_ip, int(listen_port))) != 0: print("Failed to connect %s:%d on %s mode:%m.\n", diff --git a/script/local/KerberosUtility.py b/script/local/KerberosUtility.py index 19e9e0e..a800cd7 100644 --- a/script/local/KerberosUtility.py +++ b/script/local/KerberosUtility.py @@ -467,8 +467,8 @@ class Kerberos(): # Every 1000 records merged into one" ipstring = "" for ip in self.__allIps: + submask_length = NetUtil.get_submask_len(ip) if not isUninstall: - submask_length = NetUtil.get_submask_len(ip) ipstring += " -h 'host all all " \ " %s/%s gss " \ "include_realm=1 krb_realm=%s'" % \ -- Gitee