日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

crt python_SecureCRT Python

發布時間:2025/5/22 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 crt python_SecureCRT Python 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

學完python后需要學以致用,但平時還真沒有這個環境,也不搞自動化,但語言這玩意必需要用,就拿secureCRT來練手吧,也算是和工作擦點邊

對話框加按扭

CONFIRM_REPLACE = """\ #為數不多的button判斷

Do you want to replace the contents of "%(FILE)s" with the selected text?

Yes = overwrite

No = append

Cancel = end script"""

message = CONFIRM_REPLACE % { 'FILE' : "filename" }

prompt = "Replace contents"

buttons = BUTTON_YESNOCANCEL

result = crt.Dialog.MessageBox(message, prompt, buttons)

if result == IDYES:

fileMode = "w"

elif result == IDNO:

fileMode = "a"

crt.Dialog.Prompt( #超級有用的在用戶這獲取數據的方式

"Save selected text to File:",

"SecureCRT - Save selected text to file",

"MyFile.txt")

獲取log文件名在SecureCRT

tab = crt.GetScriptTab()

tab.Session.LogFileName

#如果在CRT中設置了log文件名,這個函數可以把它讀取出來

#可以直接取到log的文件名 獲取系統當前的前綴名

SCRIPT_TAB = crt.GetScriptTab()

rowIndex = SCRIPT_TAB.Screen.CurrentRow

colIndex = SCRIPT_TAB.Screen.CurrentColumn - 1

prompt = SCRIPT_TAB.Screen.Get(rowIndex, 0, rowIndex, colIndex)

#獲取當前行,當前列的數據,即該服務器的前綴,與waitfor配套

prompt = prompt.strip()

獲取打印值

def CaptureOutputOfCommand(command, prompt):

if not crt.Session.Connected:

return "[ERROR: Not Connected.]"

# First, send the command to the remote.

SCRIPT_TAB.Screen.Send(command + '\r')

#輸入命令 cmmand 然后回車

# Second, wait for the carriage return to be echoed by the remote device.

# This allows us to capture only the output of the command, not the line

# on which the command was issued (which would include the prompt + cmd).

# If you want to capture the command that was issued, simply comment out

# the following line of code.

SCRIPT_TAB.Screen.WaitForString('\r'

#等待命令輸完后,服務器給的回應,這樣可以不是獲取行,而是獲取輸出

# Now that the command has been sent, use Screen.ReadString to capture

# all the data that is received up to the point at which the shell

# prompt appears (the captured data does not include the shell prompt).

return SCRIPT_TAB.Screen.ReadString(prompt)

#獲取直到prompt出現時的所有數據

屏幕取詞

filename = os.path.join(os.path.expanduser('~'), 'output.txt') #~/output.txt

fp = open(filename, "wb+")

screenrow = crt.Screen.CurrentRow - 1

readline = crt.Screen.Get(screenrow, 1, screenrow, 20)

#把當前行的1~20個字符取出來

fp.write(readline + os.linesep)

#把取出的那一行加行尾符寫到文件中

寫到excel

import os

import csv #excel module

fileobj = open(filename, 'wb')

worksheet = csv.writer(fileobj)

worksheet.writerow(items[:2])

fileobj.close(

連接

SSH:

cmd = "/SSH2 /L %s /PASSWORD %s /C 3DES /M MD5 %s" % (user, passwd, host)

crt.Session.Connect(cmd) #ssh -L user password host

Telnet:

crt.Session.Connect("/TELNET 127.0.0.1 2034") # telnet 127.0.0.1:2034

crt.Session.Connect("/S \"" + session + "\"")

#如果這個session在CRT里存在,無論是Telnet還是SSH都能連

調試工具 CRT中的print

crt.Dialog.MessageBox("Nothing to save!")

參考:

http://www.vandyke.com/support/securecrt/python_examples.html

總結

以上是生活随笔為你收集整理的crt python_SecureCRT Python的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。