当前位置:   article > 正文

ctf之AWD(2)_多线程_awd解题

awd解题

ctf之AWD(2)_多线程

# -*- coding:utf-8 -*-
import threading,queue,time

base_url = "http://192.168.1."
url_queue = queue.Queue()

for i in range(1,31):
    url = base_url+str(i)
    url_queue.put(url)

def fetUrl(url_queue):
    while url_queue.qsize()>0:
        try:
            # 不阻塞的读取队列数据
            url = url_queue.get_nowait()
            i = url_queue.qsize()
        except Exception as e:
            print(e)
            break
        print('Current Thread Name %s, Url: %s ' % (threading.currentThread().name, url))

if __name__ == '__main__':
    startTime = time.time()
    threads = []
    threadNum = 4
    for i in range(0,threadNum):
        try:
            t = threading.Thread(target=fetUrl,args=(url_queue,))
            threads.append(t)
        except:
            print("加入线程失败")
            break
    for t in threads:
        try:
            t.start()
        except:
            print('开启线程失败')
            break
    for t in threads:
        try:
            t.join()
        except:
            print('启动线程失败')
            break
    endTime = time.time()
    print('Done, Time cost: %s ' % (endTime - startTime))

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/663144
推荐阅读
相关标签
  

闽ICP备14008679号