0
我正嘗試使用以下功能爲一組Windows Server創建庫存報告。但是,這個函數總是對所有主機的ping測試失敗,儘管我們可以從命令行乾淨地ping通一些主機。 嘗試了多種組合,無法弄清楚限制它打ping通路塊的是什麼? ! 請建議,使用python的Windows庫存
def StartInvetoryCollection() :
for eachline in open('HostList.txt', 'r') :
RemoteHost = eachline.strip()
print(RemoteHost, end='')
if os.system('ping RemoteHost -c 4') == 0 :
print('\t\tPING=PASS',end='')
ReportFileName = RemoteHost + '_msinfo.txt'
os.system('msinfo32 /computer Host /report ReportFileName')
print('\tData Collection=PASS')
else :
print('\t\tPING=FAIL\tData Collection=SKIP')
pass
Hostlist.txt - 每行包含
感謝您的FO響應Tony.D,但這也不會通過部分。我只在hostname.txt中保留'localhost',但ping報告也失敗了。 –
如果你刪除'-c 4',它會工作 –
**感謝Tiny.D!**,現在工作。但是如果我想要包含命令標記呢。 –