bobbai 发表于 2018-8-9 12:46:21

Python多线程拼网段地址脚本

  正常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=)    多线程命令
  a.start()                                       输出执行结果
页: [1]
查看完整版本: Python多线程拼网段地址脚本