如何批量檢測主機IP并把結果生成excel文件表格,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
這是對上一個腳本的擴展,增加了生成excel表格
#coding=gbk
import os
import sys
import xlwt
wk = xlwt.Workbook(encoding = 'utf-8')
sheet1 = wk.add_sheet("IP62",cell_overwrite_ok=True)
style = xlwt.XFStyle()
sheet1.write(0, 0,'ip地址',style)
sheet1.write(0,1, '狀態',style)
x = y = 0
for ip in range(1,255):
res = os.system('ping -n 1 -w 1 '+sys.argv[1]+str(ip))
if res == 0:
print(sys.argv[1]+str(ip)+' up')
sheet1.write(ip,0,sys.argv[1]+str(ip))
sheet1.write(ip,1,'up')
x += 1
else:
print(sys.argv[1]+str(ip)+' down')
sheet1.write(ip,0,sys.argv[1]+str(ip))
sheet1.write(ip,1,'down')
y += 1
print('total up ip is '+str(x))
print('total down ip is '+str(y))
sheet1.write(ip+1,0,'total up ip is '+str(x))
sheet1.write(ip+2,0,'total down ip is '+str(y))
wk.save('ip.xls')
看完上述內容,你們掌握如何批量檢測主機IP并把結果生成excel文件表格的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。