2017-05-30 84 views
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 - 每行包含

回答

0

你有一个主机名到你的价值传递到os.system

def StartInvetoryCollection() : 
    for eachline in open('HostList.txt', 'r') : 
     RemoteHost = eachline.strip() 
     print(RemoteHost, end='') 
     if os.system('ping {} -n 4'.format(RemoteHost)) == 0 : 
      print('\t\tPING=PASS',end='') 
      ReportFileName = RemoteHost + '_msinfo.txt' 
      os.system('msinfo32 /computer Host /report {}'.format(ReportFileName)) 
      print('\tData Collection=PASS') 
     else : 
      print('\t\tPING=FAIL\tData Collection=SKIP') 
      pass 
+0

感谢您的FO响应Tony.D,但这也不会通过部分。我只在hostname.txt中保留'localhost',但ping报告也失败了。 –

+0

如果你删除'-c 4',它会工作 –

+0

**感谢Tiny.D!**,现在工作。但是如果我想要包含命令标记呢。 –