|
本帖最后由 vinsonpyg 于 2018-8-3 14:54 编辑
#coding:utf-8
import wmi
import os
import ConfigParser
import sys
from threading import Thread
from optparse import OptionParser
rootDir = os.path.split(os.path.realpath(__file__))[0]
configFilePath = os.path.join(rootDir, 'config.ini')
config = ConfigParser.ConfigParser()
config.read(configFilePath)
# ip = config.get('access','ip')
# print ip
username = config.get('access','user')
print username
passwd = config.get('access','password')
print passwd
app1 = config.get('path',r'app1')
ad18 = config.get('path',r'app2')
# ad17 = config.get('path',r'app3')
# ad16 = config.get('path',r'app4')
# ad15 = config.get('path',r'app5')
# ad14 = config.get('path',r'app6')
# ad10 = config.get('path',r'app7')
# ad09 = config.get('path',r'app9')
# ad06 = config.get('path',r'app10')
# ad04 = config.get('path',r'app11')
# ad03 = config.get('path',r'app12')
def readfile():
usage = "usage: %prog -f <filename> -i <ip address>"
parser = OptionParser(usage=usage)
parser = OptionParser()
parser.add_option("-f","--file",type="string",dest="filename",help="specify the ip address file")
parser.add_option("-i","--ip",type="string",dest="address",help="specify the ipaddress")
(opti**,args)=parser.parse_args()
filename = opti**.filename
address = opti**.address
if filename==None and address == None:
print "please give me a ip list files"
if filename:
if not os.path.exists(filename):
print "this file is not exists,please make sure the path is right"
sys.exit()
f = open(filename,'r')
for i in f.readlines():
ip = i.strip()
def remote(ip,username,passwd):
try:
conn = wmi.WMI(computer=ip,user=username,password=passwd)
pro1 = conn.ExecQuery("select * from CIM_DATAFILE where name = '%s'"% app1)
pro2 = conn.ExecQuery("select * from CIM_DATAFILE where name = '%s'"% ad18)
for pc in conn.ExecQuery("select * from win32_computersystem"):
pass
for p1 in pro1:
print (p1.Readable)
if p1.Readable == True:
print ip +"," + pc.name +"," +("app1 is done")
else:
pass
for p2 in pro2:
if p2.Readable == True:
print ip + pc.name +("app2 is done")
else:
pass
except Exception,e:
print str (e)
if __name__ == "__main__":
remote()
|
|