Skip to content

Instantly share code, notes, and snippets.

@songtianlun
Created November 17, 2020 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save songtianlun/864e1f66848a1fb865589c8aaa34f71f to your computer and use it in GitHub Desktop.
Save songtianlun/864e1f66848a1fb865589c8aaa34f71f to your computer and use it in GitHub Desktop.
# $language = "python"
# $interface = "1.0"
# This automatically generated script may need to be
# edited in order to work correctly.
import time
import math
import random
start_time = time.time()
end_time = time.time()
cmd = "show sw"
cmd_list = [
'show interface switchport xge 1/0/20',
'show vlan all',
'show arp all',
'show mac-address all',
'show trap message filter level 1'
]
cmd_list_len = len(cmd_list) - 1
time_sleep = 0.1
time_out = 30
def Main():
crt.Screen.Send("co te\r\n")
crt.Screen.Send("int xge 1/0/6\r\n")
while True:
end_time = time.time()
crt.Screen.Synchronous = False
#crt.Screen.Send(cmd)
CmdNum = random.randint(0,cmd_list_len)
crt.Screen.Send(cmd_list[CmdNum])
crt.Screen.Send("\r\n")
running_time = end_time - start_time
running_min = math.ceil(running_time / 60) - 1
if (crt.Screen.WaitForCursor(time_out)):
#crt.Screen.Send("\r\n")
#crt.Screen.Send("\r\n")
#crt.Screen.Send("\r\n")
#crt.Screen.Send("\r\n")
#crt.Screen.Send("\r\n")
if CmdNum == 10:
time.sleep(10)
else:
time.sleep(time_sleep)
#time.sleep(100 / (running_time / 1000))
else:
msg = "超时无响应,运行报告:\n" + \
"running time : " + str( running_min ) + " min " + str(running_time - running_min * 60 - time_out) + " s " + "\n" + \
"start ms : " + str(start_time) + "\n" + \
"ent ms : " + str(end_time) + "\n"
crt.Dialog.MessageBox(msg,"session",64|2)
Main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment