python实现多线程软件分发(局域网)
程序说明:
1、适用于局域网C类地址,如要适用CIDR,则需要改造程序;
2、多并发下发软件,但没有进行安装;
3、需要有远程PC的管理员帐号密码,比较适合域控环境;
4、比较适合企业IT管理员使用。
#-*- coding:cp936 -*-
#import sys
#reload(sys)
#sys.setdefaultencoding('utf8')
import subprocess
import threading
import os
print '开启软件分发程序'
print '-----------------------------------'
ipstart=raw_input('请键入你的起始IP地址 :')
ipend=raw_input('请键入你的结束IP地址 :')
user=raw_input('请输入客户端的管理员用户 :')
password=raw_input('请输入客户端管理员密码 :')
print '-----------------------------------'
print '\n'
ipstart='x.x.x.x'
ipend='x.x.xx'
user='xxx'
password='xxx'
ipstartlist=ipstart.split('.')
ipendlist=ipend.split('.')
a=ipstartlist[0]
b=ipstartlist[1]
c=ipstartlist[2]
start=int(ipstartlist[3])
end=int(ipendlist[3])
cmd="cmd.exe"
f=open(r'c:\cmd.txt','a')
h=1
n=1
#线程数
ep=(end-start+1)/n
remain=(end-start+1)%n
def deploy(start1,end1):
global h
while start1 <= end1:
p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
#ping 进程
pp=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
#net use进程
ppp=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
#copy进程
ipk=a,b,c,str(start1)
ip='.'.join(ipk)
cmd1=r'net use \\%s\ipc$ "%s" /user:"%s"'%(ip,password,user)+"\n"
cmd2=r'cmd /k xcopy /i /s /e /y D:\winxp\*.* \\"%s"\c$\winxp'%ip+"\n"
p.stdin.write("ping %s"%ip+"\n")
p.stdin.close()
#pp.wait()
print p.stdout.read()
pout=p.communicate()[0]
if pout.find('Reply from')>=0:
print '(%s)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&'%h
print '* %s 客户端在线!!!'%ip
pp.stdin.write(cmd1)
pp.stdin.close()
#p.wait()
ppout=pp.stdout.read()
if ppout[143:145]=='命':
print "* 成功连接客户端: %s"%ip
print '\n'
f.write('%s %s 成功连接客户端'%(h,ip)+'\n')
f.write('\n')
ppp.stdin.write(cmd2)
ppp.stdin.close()
#ppp.wait()
pppout=ppp.stdout.read()
if pppout.find('11')==468:
f.write('%s %s 成功复制所有文件'%(h,ip)+'\n')
print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
print '\n'
else:
print "文件复制失败"
f.write('%s 文件复制失败'%ip)
print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
print '\n'
else:
print "* 客户端:%s连接失败"%ip
print '\n'
f.write('%s %s 客户端连接失败'%(h,ip)+'\n')
f.write('\n')
else:
print '\n\n'
print '(%s)##################################################'%h
print '* %s 客户端不在线'%ip
print '####################################################'
print '\n'
f.write('%s %s 客户端不在线'%(h,ip)+'\n')
start1=start1+1
h=h+1
if __name__=='__main__':
threads=[]
if ep >=1:
if remain == 0:
for i in xrange(0,n):
d=start+i*ep
endd=start+ep*(i+1)-1
threads.append(threading.Thread(None,target=deploy,args=(d,endd)))
else:
for i in xrange(0,n):
d=start+i*ep
endd=start+ep*(i+1)-1
threads.append(threading.Thread(None,target=deploy,args=(d,endd)))
threads.append(threading.Thread(None,target=deploy,args=(start+n*ep,end)))
else:
threading.Thread(None,target=deploy,args=(start,end))
for t in threads:
t.start()
for t in threads:
t.join()

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
Java Spring常见面试题
问:SpringIOC原理阐述 答:把对象的创建、初始化、销毁等工作交给Spring容器来完成。我们可以把IOC容器的工作模式看做是工厂模式的升华,可以把IOC容器看作是一个工厂,这个工厂里要生产的对象都在配置文件中给出定义,然后利用编程语言的的反射编程,根据配置文件中给出的类名生成相应的对象。从实现来看,IOC是把以前在工厂方法里写死的对象生成代码,改变为由配置文件来定义,也就是把工厂和对象生成这两者独立分隔开来,目的就是提高灵活性和可维护性。 问:SpringAOP原理 答:1)面向对象的设计没有办法解决重复代码的问题 2)SpringAOP使用动态代理技术在运行期植入增强的代码,aspectj是在编译器织入横切代码的形式来实现代理技术的 3)SpringAOP使用了两种代理机制,一种是基于JDK的动态代理,一种是基于CGLib的动态代理 4)JDK1.3以后java提供了动态代理的技术,运行开发者在运行期创建接口的代理实例 5)jdk的动态代理主要涉及java.lang.reflect包中的两个类ProxyInvcoationHandler 6)InvcoationHandler...
-
下一篇
javascript的一些命名约定
这篇小文章主要是通过一些例子来介绍一些Javascript中一些关于命名变量,函数,类或者是组件的通用约定。虽然这些规则并不是强制性的,但是呢,他们却被一些JS社区所广泛采用,所以,了解他们还是很有必要的。 Javascript命名约定:变量 由于Javascript是大小写敏感的,因此,如果有几个变量,其仅仅是大小写不一样,这些变量在Javascript中会被理解为是不同的变量,如下所示: var name = 'Robin Wieruch'; var Name = 'Dennis Wieruch'; var NAME = 'Thomas Wieruch'; console.log(name); // "Robin Wieruch" console.log(Name); // "Dennis Wieruch" console.log(NAME); // "Thomas Wieruch" 一个好的javascript变量名是应该能描述出他这个变量所代表的含义,因此,一般情况下,如果变量名足够清晰的话,给其增加一个注释可能没太多必要。 // bad var value = 'Robin'...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS关闭SELinux安全模块
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- MySQL数据库在高并发下的优化方案
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- MySQL8.0.19开启GTID主从同步CentOS8
- SpringBoot2全家桶,快速入门学习开发网站教程
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Dcoker安装(在线仓库),最新的服务器搭配容器使用
- Docker使用Oracle官方镜像安装(12C,18C,19C)