0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內(nèi)不再提示

Netmiko+excle定時檢測接口狀態(tài)

jf_yLA7iRus ? 來源:知乎楓嵐 ? 作者:知乎楓嵐 ? 2022-10-19 09:15 ? 次閱讀

一、前言:在本人看著群里的大佬紛紛分享自己的文章和一些運維思路,深知只有用出來,寫出來,分享出來,跟大家一起交流,這個程序和學習到的新知識才算真正掌握了。在這里非常感謝王印王老師@弈心、朱嘉盛老師@朱嘉盛以及群里的各位大佬不遺余力地分享著自己的文章。針對python的學習主要源于他們的專欄。

二、實驗背景:

前一段時間,機房剛剛建完,但是弱電做的網(wǎng)線不太行,出現(xiàn)兩次網(wǎng)線問題,這不是要了命了么。領導說,想辦法如果交換機網(wǎng)線出問題了你得能知道。我想說,咱們用個運維平臺不行嗎,我又想我們今年手里的服務器資源只剩下4核,6G了。
行,那就寫個腳本吧。本次實驗以H3C設備為基礎。

就是說寫一個只要接口狀態(tài)發(fā)生變化就能有郵件通知你,而且還有excle作為佐證。

我認為本次實驗僅僅適用于十幾二十臺小環(huán)境的網(wǎng)絡。(而且有點錢上個平臺不比嘛強)

三、需求分析

首先首次使用腳本之后,excle里工作表收集的都是當前所有設備的UP的接口。

81f94692-4f45-11ed-a3b6-dac502259ad0.jpg

工作簿底下的工作表的是所有設備,以命名+IP的形式存在。

822ed49c-4f45-11ed-a3b6-dac502259ad0.jpg

工作簿底下是所有的設備

然后如果有一個接口的狀態(tài)出現(xiàn)了變化,只要有變化,Link這一列對應的狀態(tài)就會變色,還會發(fā)郵件以工作簿為附件。

824087fa-4f45-11ed-a3b6-dac502259ad0.jpg

82770eec-4f45-11ed-a3b6-dac502259ad0.jpg

如果你是就想人為規(guī)劃斷開這個接口,不是鏈路的損壞,那么在下次執(zhí)行這個腳本的時候,不是UP接口就不存在了。

82a1a1e8-4f45-11ed-a3b6-dac502259ad0.jpg

如果這個接口從ADM狀態(tài)又回復為UP,那么也會發(fā)郵件,并且攜帶工作簿為附件。

82affcb6-4f45-11ed-a3b6-dac502259ad0.jpg

81f94692-4f45-11ed-a3b6-dac502259ad0.jpg

最后設置成1分鐘執(zhí)行一次,放在服務器里。

每次執(zhí)行程序只會維護第一次執(zhí)行程序輸出的這一張表,所以不用擔心文件太多。

三、代碼分析

3.1完整代碼

先上完整代碼,然后再進行分析。

#coding=gbk
importre
importsmtplib
importthreading
importtime
fromemail.mime.applicationimportMIMEApplication
fromemail.mime.multipartimportMIMEMultipart
fromemail.mime.textimportMIMEText
frompprintimportpprint
fromqueueimportQueue

fromnetmikoimportConnectHandler
fromopenpyxl.reader.excelimportload_workbook
fromopenpyxl.workbookimportWorkbook
fromopenpyxl.stylesimportPatternFill,Border,Side,Font

threads=[]#用于多線程
ip_list=open('ip_file.txt')#IP地址先行放入文件中
dims={}#用于對工作表中自動設置最大行寬
content=""#用于輸出在郵箱中的內(nèi)容
defssh_seesion(ip,ouput,):
globalcontent,sheet
#這幾個列表是寫入工作表的先行條件,也就是工作表的每一列,先把想寫入工作表的每一列的內(nèi)容寫入列表,然后再遍歷列表把內(nèi)容寫入工作表
interface_list=[]
link_list=[]
speed_list=[]
description_list=[]

connection_info={'device_type':'hp_comware',
'ip':ip,
'username':'xxxxx',
'password':'xxxxxx'}

withConnectHandler(**connection_info)asconn:
output=conn.send_command("displayinterfacebrief",use_textfsm=True)
sysname=conn.send_command('displaycurrent-configuration|includesysname')
name=re.search(r's+S+s+(S+)',sysname).groups()[0]
#pprint(output)

try:
sheet=wb[name+'_'+ip]#調(diào)用自己的那一張表
#先給逼刪了
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
num=re.search('d+',i.coordinate).group()#找到需要刪的那一行
print(num)
sheet.delete_rows(int(num))
except:
pass

#取出接口up的
foriinoutput:
ifi.get('link')=='UP':
interface_list.append(i.get('interface'))
link_list.append(i.get('link'))
speed_list.append(i.get('speed'))
description_list.append(i.get('description'))
#判斷這次interface跟上次也就是表格里的有沒有區(qū)別以是否是UP的為前提不是UP的或者多了UP的或者少了UP的只要變化就要被記錄


ifstr(name+'_'+ip)inwb.sheetnames:#如果這個表存在就讓里原本有的接口進入列表
sheet_pre=wb[name+'_'+ip]
column_A=sheet_pre['A']#取出以前的表的第一列
sheet_pre_A1=[i.valueforiincolumn_A]
sheet_pre_A1.remove('Interfaces')#遍歷第一列的時候會有抬頭也就是Interfaces'需要把這個去掉
#print(sheet_pre_A1)#sheet_pre_A1里是上一次表格里有的接口列表
#print(interface_list)#interface_list里是這一次想放入表格里的UP的接口的列表
#取出兩個列表的差集,這個差集是現(xiàn)在UP的和表里的差集
sheet_dif=list(set(sheet_pre_A1)^(set(interface_list)))#把兩個表中變化的接口放入sheet_dif這個列表里
print(sheet_dif)#至此有變化的且不是UP的接口就進入列表了
iflen(sheet_dif)!=0:#如果這個列表里有數(shù)據(jù)就發(fā)郵箱
content=content+f"{name}{str(sheet_dif)}接口發(fā)生了變化
'"#配合發(fā)郵件的

foriinoutput:#為了把差集的接口情況寫入列表
forpinsheet_dif:
ifp==i.get('interface')andi.get('link')!='UP':#找到這個不是UP的接口各種情況還寫進去
interface_list.append(i.get('interface'))
link_list.append(i.get('link'))
speed_list.append(i.get('speed'))
description_list.append(i.get('description'))
content=content+i.get('interface')+'接口由UP變成了'+i.get('link')+'
'
elifp==i.get('interface')andi.get('link')=='UP':
content=content+i.get('interface')+'接口UP了'+'
'


font=Font(name="微軟雅黑",bold=True)#字體加粗
yellowFill=PatternFill(start_color='FFFF00',end_color='FFFF00',fill_type='solid')#黃色
thin_border=Border(left=Side(style='thin'),right=Side(style='thin'),top=Side(style='thin'),
bottom=Side(style='thin'))#有邊框
SpringGreen=PatternFill(start_color='3CB371',end_color='3CB371',fill_type='solid')#黃色

ifstr(name+'_'+ip)inwb.sheetnames:#如果表格存在直接往里寫
row_numbers=list(range(2,len(output)+2))#只能從第二行開始
forinterface,rowinzip(interface_list,row_numbers):
sheet.cell(row=row,column=1,value=interface)
forlink,rowinzip(link_list,row_numbers):
sheet.cell(row=row,column=2,value=link)
forspeed,rowinzip(speed_list,row_numbers):
sheet.cell(row=row,column=3,value=speed)
fordescription,rowinzip(description_list,row_numbers):
sheet.cell(row=row,column=4,value=description)

#往里寫完之后查看B1這列然后找到不是UP的給賦值綠色
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
print(i.coordinate)#查找到接口有問題的坐標
sheet[i.coordinate].fill=SpringGreen


else:#如果表格不存在則創(chuàng)建表格
sheet=wb.create_sheet(name+'_'+ip)#這里的sheet相當于JT-6-1F-DAS-1這個表格
columns=['A1','B1','C1','D1']
cells=['Interfaces','Link','Speed','Description']
fori,pinzip(columns,cells):
#放入表格中
sheet[i]=p
sheet[i].fill=yellowFill
sheet[i].font=font

row_numbers=list(range(2,len(output)+2))#只能從第二行開始
forinterface,rowinzip(interface_list,row_numbers):
sheet.cell(row=row,column=1,value=interface)
forlink,rowinzip(link_list,row_numbers):
sheet.cell(row=row,column=2,value=link)
forspeed,rowinzip(speed_list,row_numbers):
sheet.cell(row=row,column=3,value=speed)
fordescription,rowinzip(description_list,row_numbers):
sheet.cell(row=row,column=4,value=description)


forrowinsheet.rows:
#print(row)
forcellinrow:
#print(cell.value)
cell.border=thin_border
ifcell.value:
dims[cell.column_letter]=max((dims.get(cell.column_letter,0),len(str(cell.value))))

forcol,valueindims.items():
sheet.column_dimensions[col].width=value+3


defsend_email(sender,receicer,password,content):
#這份代碼比較標準了,可以直接用了

#發(fā)件人郵箱
sender=sender
#收件人郵箱
receiver=receicer
#抄送人郵箱
#acc='xxxxxxxx@qq.com'
#郵件主題
subject='服務器運行情況'

#郵箱密碼(授權(quán)碼)
password=password

#郵件設置
msg=MIMEMultipart()
msg['Subject']=subject#主題
msg['to']=receiver#接收者
#msg['acc']=acc#抄送者
msg['from']="信息化員工"#發(fā)件人

#郵件正文
content=content

#添加郵件正文:
msg.attach(MIMEText(content,'plain','utf-8'))#content是正文內(nèi)容,plain即格式為正文,utf-8是編碼格式

#添加附件
#注意這里的文件路徑是斜杠
file_name=r'E:python	est	est功能腳本接口up_down	est_openpyxl.xlsx'
file_name_list=file_name.split('\')[-1]#獲得文件的名字
xlsxpart=MIMEApplication(open(file_name,'rb').read())
xlsxpart.add_header('Content-Disposition','attachment',filename=file_name_list)
#服務端向客戶端游覽器發(fā)送文件時,如果是瀏覽器支持的文件類型,一般會默認使用瀏覽器打開,比如txt、jpg等,會直接在瀏覽器中顯示,如果需要提示用戶保存,就要利用Content-Disposition進行一下處理,關(guān)鍵在于一定要加上attachment
msg.attach(xlsxpart)

#設置郵箱服務器地址以及端口
smtp_server="smtp.qq.com"
smtp=smtplib.SMTP(smtp_server,25)#'smtp.qq.com'是QQ郵箱發(fā)郵件的服務器,用新浪郵箱就是'smtp.sina.com',就是smtp加上你們郵箱賬號@符號后面的內(nèi)容。端口默認是25。
#smtp.set_debuglevel(1)#顯示出交互信息

#登陸郵箱
smtp.login(sender,password)

#發(fā)送郵件
smtp.sendmail(sender,receiver.split(','),msg.as_string())
#receiver.split(',')+acc.split(',')是['xxxxxxxx@qq.com','xxxxxxxx@qq.com']

#斷開服務器鏈接
smtp.quit()

print(f"程序于{time.strftime('%X')}執(zhí)行開始
")
#記錄開始時間
start_time=time.time()

#注意邏輯關(guān)系先創(chuàng)建工作簿再進入多線程最后保存工作簿
try:#如果存在這個表格就直接打開,如果部存在就創(chuàng)建
wb=load_workbook('test_openpyxl.xlsx')
ws=wb.active
except:#創(chuàng)建表格如果存在就不創(chuàng)建
wb=Workbook()
wb.remove(wb['Sheet'])
ws=wb.active

foripsinip_list.readlines():
t=threading.Thread(target=ssh_seesion,args=(ips.strip(),Queue()))
t.start()
threads.append(t)


foriinthreads:
i.join()
#加入檢查功能


iflen(content)!=0:
print(content)
send_email("xxxx@qq.com","xxxx@qq.com","jveyorpbogllijhj",content)


end_time=time.time()-start_time

wb.save('test_openpyxl.xlsx')#保存工作表
print(f'總共耗時{round(end_time,2)}秒')
print(f"程序于{time.strftime('%X')}執(zhí)行結(jié)束
")
TestFSM模板
ValueInterface(S+)
ValueLink(UP|DOWN|ADM|Stby)
ValueSpeed(.*G|auto)
ValueDescription(S+|s+)

Start
^s*${Interface}s+${Link}s+${Speed}((a)|s*)+s+S+s+S+s+S+s+${Description}->Record

3.2分析

特別詳細的分析寫在了代碼的注釋中。這里只是對思路的分析。

首先就是登錄設備,然后調(diào)用TestFSM模板做解析,再取出設備的名字。use_textfsm=True的用法參照朱嘉盛:《網(wǎng)絡工程師的Python之路》(nornir實驗10,聯(lián)動Textfsm,ntc-template,華為)

defssh_seesion(ip,ouput,):
globalcontent,sheet
#這幾個列表是寫入工作表的先行條件,也就是工作表的每一列,先把想寫入工作表的每一列的內(nèi)容寫入列表,然后再遍歷列表把內(nèi)容寫入工作表
interface_list=[]
link_list=[]
speed_list=[]
description_list=[]

connection_info={'device_type':'hp_comware',
'ip':ip,
'username':'xxxxxx',
'password':'123'}

withConnectHandler(**connection_info)asconn:
output=conn.send_command("displayinterfacebrief",use_textfsm=True)
sysname=conn.send_command('displaycurrent-configuration|includesysname')
name=re.search(r's+S+s+(S+)',sysname).groups()[0]
#pprint(output)

首先明確這個腳本是一分鐘執(zhí)行一次,然后是在工作簿中找到此次登錄的設備的工作表,然后對其進行刪除操作,刪除工作表中存在的不是UP的接口的那一行,因為這個工作簿的目的是存接口為UP的接口的信息,那么之前存在不是UP的接口的內(nèi)個工作簿呢?通過郵箱發(fā)出來了。因為如果第一次執(zhí)行這個程序,那么肯定不存在這個表,所以用個try……except。

i.coordinate用來獲取一個格子的坐標的。比如輸出結(jié)果就是B11這樣。

try:
sheet=wb[name+'_'+ip]#調(diào)用自己的那一張表
#先給逼刪了
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
num=re.search('d+',i.coordinate).group()#找到需要刪的那一行
print(num)
sheet.delete_rows(int(num))
except:
passtry:
sheet=wb[name+'_'+ip]#調(diào)用自己的那一張表
#先給逼刪了
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
num=re.search('d+',i.coordinate).group()#找到需要刪的那一行
print(num)
sheet.delete_rows(int(num))
except:
pass
defssh_seesion(ip,ouput,):
globalcontent,sheet
#這幾個列表是寫入工作表的先行條件,也就是工作表的每一列,先把想寫入工作表的每一列的內(nèi)容寫入列表,然后再遍歷列表把內(nèi)容寫入工作表
interface_list=[]
link_list=[]
speed_list=[]
description_list=[]

connection_info={'device_type':'hp_comware',
'ip':ip,
'username':'xxxxxx',
'password':'123'}

withConnectHandler(**connection_info)asconn:
output=conn.send_command("displayinterfacebrief",use_textfsm=True)
sysname=conn.send_command('displaycurrent-configuration|includesysname')
name=re.search(r's+S+s+(S+)',sysname).groups()[0]
#pprint(output)
然后取出接口為UP的接口的信息,放入表格中,因為這個工作簿的目的是存接口為UP的接口的信息。
#取出接口up的
foriinoutput:
ifi.get('link')=='UP':
interface_list.append(i.get('interface'))
link_list.append(i.get('link'))
speed_list.append(i.get('speed'))
description_list.append(i.get('description'))
#判斷這次interface跟上次也就是表格里的有沒有區(qū)別以是否是UP的為前提不是UP的或者多了UP的或者少了UP的只要變化就要被記錄

再然后就是把表中原有的接口記錄在sheet_pre_A1這個例表中,然后與剛才新構(gòu)成的接口全為UP的列表interface_list取差集,差集包含什么?包含可能有新接口UP了,可能有舊接口不UP了。如果差集中有接口,就寫入content中,為了發(fā)郵箱用。

然后判斷差集里面接口的狀態(tài),是又其他狀態(tài)變?yōu)閁P,還是由UP變?yōu)榱似渌麪顟B(tài)。還是寫如content中,發(fā)郵箱用。

ifstr(name+'_'+ip)inwb.sheetnames:#如果這個表存在就讓里原本有的接口進入列表
sheet_pre=wb[name+'_'+ip]
column_A=sheet_pre['A']#取出以前的表的第一列
sheet_pre_A1=[i.valueforiincolumn_A]
sheet_pre_A1.remove('Interfaces')#遍歷第一列的時候會有抬頭也就是Interfaces'需要把這個去掉
#print(sheet_pre_A1)#sheet_pre_A1里是上一次表格里有的接口列表
#print(interface_list)#interface_list里是這一次想放入表格里的UP的接口的列表
#取出兩個列表的差集,這個差集是現(xiàn)在UP的和表里的差集
sheet_dif=list(set(sheet_pre_A1)^(set(interface_list)))#把兩個表中變化的接口放入sheet_dif這個列表里
print(sheet_dif)#至此有變化的且不是UP的接口就進入列表了
iflen(sheet_dif)!=0:#如果這個列表里有數(shù)據(jù)就發(fā)郵箱
content=content+f"{name}{str(sheet_dif)}接口發(fā)生了變化
'"#配合發(fā)郵件的

foriinoutput:#為了把差集的接口情況寫入列表
forpinsheet_dif:
ifp==i.get('interface')andi.get('link')!='UP':#找到這個不是UP的接口各種情況還寫進去
interface_list.append(i.get('interface'))
link_list.append(i.get('link'))
speed_list.append(i.get('speed'))
description_list.append(i.get('description'))
content=content+i.get('interface')+'接口由UP變成了'+i.get('link')+'
'
elifp==i.get('interface')andi.get('link')=='UP':
content=content+i.get('interface')+'接口UP了'+'
'
第一行加粗并且黃色,有狀態(tài)變化的那一格是綠色。
font=Font(name="微軟雅黑",bold=True)#字體加粗
yellowFill=PatternFill(start_color='FFFF00',end_color='FFFF00',fill_type='solid')#黃色
thin_border=Border(left=Side(style='thin'),right=Side(style='thin'),top=Side(style='thin'),
bottom=Side(style='thin'))#有邊框
SpringGreen=PatternFill(start_color='3CB371',end_color='3CB371',fill_type='solid')#黃色
然后開始往工作表里寫東西,如果工作表存在,那么直接寫,相當于覆蓋。
寫完之后查看B1這一列,也就是Link這一列,不是UP的給賦值綠色。
ifstr(name+'_'+ip)inwb.sheetnames:#如果表格存在直接往里寫
#在寫之前先刪除#去表格里找,如果檢測到上次接口不是up則把這個接口刪掉,不是從python的列表里刪掉,直接從表格里刪掉

row_numbers=list(range(2,len(output)+2))#只能從第二行開始
forinterface,rowinzip(interface_list,row_numbers):
sheet.cell(row=row,column=1,value=interface)
forlink,rowinzip(link_list,row_numbers):
sheet.cell(row=row,column=2,value=link)
forspeed,rowinzip(speed_list,row_numbers):
sheet.cell(row=row,column=3,value=speed)
fordescription,rowinzip(description_list,row_numbers):
sheet.cell(row=row,column=4,value=description)
#往里寫完之后查看B1這列然后找到不是UP的給賦值綠色
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
print(i.coordinate)#查找到接口有問題的坐標
sheet[i.coordinate].fill=SpringGreen
如果表格不存在則創(chuàng)建表格再往里寫,服務于第一次執(zhí)行程序
else:#如果表格不存在則創(chuàng)建表格
sheet=wb.create_sheet(name+'_'+ip)#這里的sheet相當于JT-6-1F-DAS-1這個表格
columns=['A1','B1','C1','D1']
cells=['Interfaces','Link','Speed','Description']
fori,pinzip(columns,cells):
#放入表格中
sheet[i]=p
sheet[i].fill=yellowFill
sheet[i].font=font

row_numbers=list(range(2,len(output)+2))#只能從第二行開始
forinterface,rowinzip(interface_list,row_numbers):
sheet.cell(row=row,column=1,value=interface)
forlink,rowinzip(link_list,row_numbers):
sheet.cell(row=row,column=2,value=link)
forspeed,rowinzip(speed_list,row_numbers):
sheet.cell(row=row,column=3,value=speed)
fordescription,rowinzip(description_list,row_numbers):
sheet.cell(row=row,column=4,value=description)
一段以一列中最寬的一格為標準,自動變換列寬的代碼
forrowinsheet.rows:
#print(row)
forcellinrow:
#print(cell.value)
cell.border=thin_border
ifcell.value:
dims[cell.column_letter]=max((dims.get(cell.column_letter,0),len(str(cell.value))))

forcol,valueindims.items():
sheet.column_dimensions[col].width=value+3
然后是發(fā)郵件的函數(shù),就不做過多介紹了
defsend_email(sender,receicer,password,content):

最后執(zhí)行主函數(shù)

先是創(chuàng)建工作簿,因為可能工作簿已經(jīng)存在了,所以用try,然后用了多線程快一點,再然后判斷content里是否有內(nèi)容,只要接口發(fā)生了狀態(tài)變化content中就有變化,content有變化就發(fā)郵件,郵件附件是工作簿。

print(f"程序于{time.strftime('%X')}執(zhí)行開始
")
#記錄開始時間
start_time=time.time()

#注意邏輯關(guān)系先創(chuàng)建工作簿再進入多線程最后保存工作簿
try:#如果存在這個表格就直接打開,如果部存在就創(chuàng)建
wb=load_workbook('test_openpyxl.xlsx')
ws=wb.active
except:#創(chuàng)建表格如果存在就不創(chuàng)建
wb=Workbook()
wb.remove(wb['Sheet'])
ws=wb.active

foripsinip_list.readlines():
t=threading.Thread(target=ssh_seesion,args=(ips.strip(),Queue()))
t.start()
threads.append(t)


foriinthreads:
i.join()
#加入檢查功能


iflen(content)!=0:
print(content)
send_email("1123824309@qq.com","1123824309@qq.com","jveyorpbogllijhj",content)


end_time=time.time()-start_time

wb.save('test_openpyxl.xlsx')#保存工作表
print(f'總共耗時{round(end_time,2)}秒')
print(f"程序于{time.strftime('%X')}執(zhí)行結(jié)束
")

3.3思路合集

82c9c25e-4f45-11ed-a3b6-dac502259ad0.jpg

四、測試

首先用四個設備做測試

82d72ca0-4f45-11ed-a3b6-dac502259ad0.jpg

第一次執(zhí)行成功輸出工作簿,下面的工作表示以名字_ip展現(xiàn)

82e908da-4f45-11ed-a3b6-dac502259ad0.jpg

然后然別斷開兩個設備的兩個接口之后再執(zhí)行一次程序

8304208e-4f45-11ed-a3b6-dac502259ad0.jpg

831bca4a-4f45-11ed-a3b6-dac502259ad0.jpg

如果此時你就是想把這個接口認為donw掉,然后再執(zhí)行一次程序,也不會有郵件發(fā)出,down掉的接口的那一行也被刪除了

8337a878-4f45-11ed-a3b6-dac502259ad0.jpg

如果此時接口恢復UP,會發(fā)郵件通知,而且UP的接口也進入到工作表中了。

836b444e-4f45-11ed-a3b6-dac502259ad0.jpg

839fc1d8-4f45-11ed-a3b6-dac502259ad0.jpg

五、總結(jié)

最后把這個腳本仍在服務器里,一分鐘執(zhí)行一次,這樣一個低成本的監(jiān)控交換機接口狀態(tài)變化的腳本就寫完了,其實還有點小問題,比如果接口狀態(tài)不是up了,在輸出工作表時,不是UP的那一行就變?yōu)榱俗詈笠恍小?/span>

在上大學有一門課叫軟件工程,我記得老師教的一句話是”程序開發(fā)時要高內(nèi)聚,低耦合。”然后再看一眼我的代碼,真的是有些丑陋,寫程序時常常思維不清晰,邏輯不準確。反正,這個腳本在我們現(xiàn)有的網(wǎng)絡里能用。

審核編輯 :李倩


聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • ADM
    ADM
    +關(guān)注

    關(guān)注

    0

    文章

    30

    瀏覽量

    15968
  • 弱電
    +關(guān)注

    關(guān)注

    0

    文章

    77

    瀏覽量

    14663
  • python
    +關(guān)注

    關(guān)注

    53

    文章

    4753

    瀏覽量

    84076

原文標題:網(wǎng)工Python之路之Netmiko+excle定時檢測接口狀態(tài)

文章出處:【微信號:釋然IT雜談,微信公眾號:釋然IT雜談】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏

    評論

    相關(guān)推薦

    電流檢測器件的數(shù)字接口

    電子發(fā)燒友網(wǎng)站提供《電流檢測器件的數(shù)字接口.pdf》資料免費下載
    發(fā)表于 09-19 13:21 ?0次下載
    電流<b class='flag-5'>檢測</b>器件的數(shù)字<b class='flag-5'>接口</b>

    ON狀態(tài)下高壓側(cè)開關(guān)開路負載檢測應用說明

    電子發(fā)燒友網(wǎng)站提供《ON狀態(tài)下高壓側(cè)開關(guān)開路負載檢測應用說明.pdf》資料免費下載
    發(fā)表于 09-13 10:19 ?0次下載
    ON<b class='flag-5'>狀態(tài)</b>下高壓側(cè)開關(guān)開路負載<b class='flag-5'>檢測</b>應用說明

    請問電池在充電狀態(tài)怎么檢測電池實際電壓?

    電池在充電狀態(tài)怎么檢測電池實際電壓?
    發(fā)表于 07-26 06:29

    定時器的工作方式介紹

    定時器是計算機和嵌入式系統(tǒng)中常見的一種硬件模塊,用于實現(xiàn)定時和計數(shù)功能。定時器的工作方式通常由一組寄存器來控制,這些寄存器定義了定時器的配置參數(shù)和工作
    的頭像 發(fā)表于 07-12 10:29 ?449次閱讀

    武漢凱迪正大分享高壓電纜狀態(tài)檢測檢測知識

    高壓電纜狀態(tài)檢測是指通過各種技術(shù)手段對高壓電纜的運行狀態(tài)進行實時監(jiān)測、評估和預測以確保電纜的安全可靠運行。本文將依照武漢凱迪正大的經(jīng)驗探討高壓電纜狀態(tài)
    的頭像 發(fā)表于 06-25 09:14 ?237次閱讀
    武漢凱迪正大分享高壓電纜<b class='flag-5'>狀態(tài)</b><b class='flag-5'>檢測</b>的<b class='flag-5'>檢測</b>知識

    使用定時器的編碼器接口模式,打開定時器的溢出中斷,當定時器上溢出和下溢出是,是否都會產(chǎn)生溢出中斷?

    使用定時器的編碼器接口模式,打開定時器的溢出中斷,當定時器上溢出和下溢出是,是否都會產(chǎn)生溢出中斷
    發(fā)表于 05-24 07:41

    s7200定時器的五種故障介紹

    定時器或CPU故障:如果定時器本身或PLC的CPU出現(xiàn)故障,也可能導致定時器無法復位。此時,需要檢查定時器和CPU的工作狀態(tài),確保其正常運行
    的頭像 發(fā)表于 04-03 17:08 ?1758次閱讀

    圓心定位大揭秘!如何快速檢測按鈕居中狀態(tài)?

    相信大家對以下這個按鍵一定不陌生,大多數(shù)電子產(chǎn)品上都少不了這個按鍵,我們通常把它稱為【電源鍵】;電源鍵在電子設備中的應用非常廣泛,是用戶與設備交互的重要接口之一。Q如何做到每個電源鍵的定位都如此精準
    的頭像 發(fā)表于 04-02 08:23 ?205次閱讀
    圓心定位大揭秘!如何快速<b class='flag-5'>檢測</b>按鈕居中<b class='flag-5'>狀態(tài)</b>?

    斷電延時定時器指令TOF

    TOF指令用于允許輸入端斷開后的單一間隔定時。當定時器的輸入端IN為ON時,TOF的狀態(tài)位為ON,其常開觸點閉合,常閉觸點斷開,但是定時器的當前值仍為0。
    的頭像 發(fā)表于 04-01 11:40 ?2184次閱讀
    斷電延時<b class='flag-5'>定時</b>器指令TOF

    window10下載了STLINK接口檢測,卻檢查不到接口怎么解決?

    window10下載了STLINK接口檢測,卻檢查不到接口,開發(fā)板沒辦法使用自帶的STLINK仿真器,想要用自己的JLINK仿真器應該怎么接線
    發(fā)表于 03-29 07:36

    Harmony 鴻蒙應用級變量的狀態(tài)管理

    應用級變量的狀態(tài)管理 在前面的章節(jié)中,已經(jīng)講述了如何管理頁面級變量的狀態(tài),本章將說明如何管理應用級變量的狀態(tài),具體接口說明請參考應用級變量的狀態(tài)
    的頭像 發(fā)表于 01-24 21:30 ?354次閱讀
    Harmony 鴻蒙應用級變量的<b class='flag-5'>狀態(tài)</b>管理

    三軸加速度計LIS2DW12開發(fā)(3)----檢測活動和靜止狀態(tài)

    檢測活動和靜止狀態(tài)主要用途是在嵌入式應用中實時監(jiān)控加速度計的活動狀態(tài),例如在可穿戴設備、智能手機或安全系統(tǒng)中檢測用戶的動作或設備的位置變化。通過設置不同的閾值和時長,可以精確地確定何時
    的頭像 發(fā)表于 12-18 10:47 ?686次閱讀
    三軸加速度計LIS2DW12開發(fā)(3)----<b class='flag-5'>檢測</b>活動和靜止<b class='flag-5'>狀態(tài)</b>

    電感如何達到飽和狀態(tài)?飽和如何影響電路?檢測電感飽和的方法

    電感如何達到飽和狀態(tài)?飽和如何影響電路?檢測電感飽和的方法? 電感的飽和狀態(tài)是指電感中的鐵芯飽和,這意味著鐵芯中的磁感應強度已經(jīng)達到了鐵芯所能承受的最大值,無法再隨著電流的增加而繼續(xù)增加。電感的飽和
    的頭像 發(fā)表于 11-29 11:09 ?1724次閱讀

    數(shù)字鎖相環(huán)狀態(tài)檢測電路

    電子發(fā)燒友網(wǎng)站提供《數(shù)字鎖相環(huán)狀態(tài)檢測電路.pdf》資料免費下載
    發(fā)表于 11-10 09:43 ?0次下載
    數(shù)字鎖相環(huán)<b class='flag-5'>狀態(tài)</b><b class='flag-5'>檢測</b>電路

    Xilinx LogiCORE IP視頻定時控制器內(nèi)核簡介

    Xilinx LogiCORE IP視頻定時控制器內(nèi)核是一款通用視頻定時生成器和檢測器。該內(nèi)核可通過完整的寄存器集進行高度編程,從而控制各種定時生成參數(shù)。這種可編程性與一組全面的中斷位
    的頭像 發(fā)表于 10-16 11:06 ?485次閱讀
    Xilinx LogiCORE IP視頻<b class='flag-5'>定時</b>控制器內(nèi)核簡介