公司需要通過腳本抓取交換機資訊,設備是H3C的。在執行“dis diagnostic-information ”這條陳述句時遇到抓取資訊不全,如果通過登錄交換機執行(保存到檔案)大概是7000行。腳本執行后只有2000多行,以下是腳本資訊:
import sys,telnetlib,time
host="192.168.1.xxx"
tn = telnetlib.Telnet(host)
print(tn.read_until(b'Username:').decode('ascii'))
tn.write(b'admin\n')
print(tn.read_until(b'Password:').decode('ascii'))
tn.write(b'admin*\n')
tn.write(b'display diagnostic-information\n')
time.sleep(120)
output=tn.read_very_eager()
filename = "1.txt"
fp = open(filename,'wb+')
fp.write(output)
fp.close()
tn.close()
read_very_eager() 這個方法查詢網上例子用的,也更換過read_all()發現執行會卡住。請教有經驗的朋友能幫下忙解釋下,小弟也是剛學習這個網上找了半天資料實在不太明白。謝謝各位
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/155825.html
上一篇:centos可以安裝DOSBox嗎?為什么配置一直不成功啊
下一篇:四則運算練習和考試兩種模式程式
