码迷,mamicode.com
首页 > 编程语言 > 详细

Python多线程拼网段地址脚本

时间:2018-02-09 20:28:12      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:cal   inux   targe   linux系统   null   get   else   导入   thread   

正常Python脚本
#!/bin/python
#coding:tuf-8 支持中文
import subprocess 加载支持Linux系统内部命令模块
def myping(x): 定义函数
m=subprocess.call(‘ping -c2 -i0.1 -w1 %s &> /dev/null‘%x,shell=‘True‘) 定义拼命令的变量
if m == 0: if判度条件
print "%s is up"%x 正确打印up
else:
print "%s is down"%x 错误打印down
ip=[‘172.40.58.%s‘%i for i in range(1,255)] 定义变量
for j in ip: for循环
myping(j) 输出最后结果

多线程脚本就比普通脚本多了两行(导入模块,执行模块命令)
 多线程Python脚本

#!/bin/python
#coding:tuf-8
import subprocess
import threading 加载多线程模块
def myping(x):
m=subprocess.call(‘ping -c2 -i0.1 -w1 %s &> /dev/null‘%x,shell=‘True‘)
if m == 0:
print "%s is up"%x
else:
print "%s is down"%x
ip=[‘172.40.58.%s‘%i for i in range(1,255)]
for j in ip:
a=threading.Thread(target=myping,args=[j]) 多线程命令
a.start() 输出执行结果

Python多线程拼网段地址脚本

标签:cal   inux   targe   linux系统   null   get   else   导入   thread   

原文地址:http://blog.51cto.com/13587114/2070736

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!