找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 1995|回复: 0

[求助] 这个脚本如果加多线程,怎么整?搞不懂多线程

1

主题

2

帖子

2

积分

贫民

积分
2
vinsonpyg 发表于 2018-8-3 14:44:59 | 显示全部楼层 |阅读模式
本帖最后由 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()
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表