python多线程下载小说章节重复_关于python设置多线程后数据重复问题

本意是想获取一个ip段的存活主机的信息,但是使用多线程后,它会重复数据:

获取信息的代码:

try:

ip = IP(self.ip)

except Exception,e:

print '%s %s:' % (colored('[*]','red'),self.ip) + 'ERROR'

exit(-1)

for Ip in ip:

ip = str(Ip)

self.qu.put(ip)

while self.qu.qsize() > 0:

try:

ip = self.qu.get()

r = requests.get('http://'+str(ip),headers=header,timeout=Timeout,allow_redirects=False)

r.encoding = 'utf-8'

status = r.status_code

title = re.search(r'

(.*)', r.text)

if title:

title = title.group(1).strip()

else:

title = 'None'

try:

banner = r.headers['server']

except:

pass

screenLock.acquire()

if status == 200 or status == 403 or status == 400:

print '%s Is scanning %s' % (colored('[+]','green'),ip)

print '%s status:%s' % (colored('[-]','blue'),status)

print '%s banner:%s' % (colored('[-]','blue'),banner)

print '%s title:%s' % (colored('[-]','blue'),title)

self.WriteOut('[%s] %s - %s - %s' % (status,ip,banner,title))

except Exception,e:

pass

finally:

screenLock.release()

设置多线程:

for i in range(args.threadNum):

t = threading.Thread(target=scan.run)

t.start()

默认线程数是20

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值