zoukankan      html  css  js  c++  java
  • mysql all_ip_test局域网IP测试工具,有需要的改一改.

     1 import threading
     2 import subprocess
     3 import pymysql
     4 # threading.Lock()
     5 
     6 
     7 class Link(object):
     8  
     9     ip = list()
    10     def __init__(self):
    11 
    12         self.connection = pymysql.connect(host='localhost', port=3306, user='**', passwd='**', db='**',
    13                                      charset='utf8', autocommit=True)
    14         
    15         self.cursor = self.connection.cursor()
    16 
    17         sql = "select ip from ip"  
    18         self.all = self.cursor.execute(sql)
    19         for i in self.cursor.fetchall():
    20             Link.ip.append(i[0])
    21         self.lock = threading.Lock()    
    22 
    23 
    24     def ping_ip(self,ip):
    25 
    26         res = subprocess.call('ping -n 4 -w 5 %s' % ip, stdout=subprocess.PIPE)
    27         print(res,">>>",ip,"<<<")
    28         if res == 0:
    29 
    30             sql = """UPDATE ip SET action = '在线' where ip like '%{}';"""  .format(ip)
    31             self.lock.acquire()     
    32             self.cursor.execute(sql)
    33             self.lock.release()     
    34             print('',ip)
    35         else:
    36             print("不通",ip)
    37 
    38 
    39     def run(self):
    40         for i in Link.ip:  # global take
    41             take = threading.Thread(target=self.ping_ip,args=(i,))
    42             take.start()
    43 
    44         take.join()
    45 
    46 
    47 def main():
    48     run = Link()
    49     run.run()
    50 
    51 
    52 
    53 
    54 if __name__ == '__main__':
    55     main()

  • 相关阅读:
    meta属性
    博客
    概念术语
    装饰器与生成器
    Linux基础
    线程
    网络编程之socket
    网络编程之网络基础部分

    内置函数(max,min,zip)及文件处理
  • 原文地址:https://www.cnblogs.com/vip136510786/p/13272611.html
Copyright © 2011-2022 走看看