Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import socket, threading
- out = []
- lock = threading.Lock()
- total_thread = 200
- #Creat new out file
- open("out.txt", "w").close()
- def worker(urls):
- global out
- print "Start thread"
- for url in urls:
- url = url.replace("http", "").strip()
- s = socket.socket()
- try:
- s.connect((url, 80))
- except:
- print "Can't connect to "+url
- continue
- req = "GET / HTTP/1.1\r\n"
- req += "Host: "+url+"\r\n"
- req += "Content-type: text/html\r\n\r\n"
- s.send(req)
- res = s.recv(20)
- s.close()
- if(res.find("200") != -1 or res.find("302") != -1 or res.find("301") != -1):
- print url+" Oke"
- out.append(url)
- wTf()
- def wTf():
- global out
- if(len(out) > 400):
- lock.acquire()
- with open("out.txt", "a") as ff:
- ff.write("\r\n".join(out))
- out = []
- print "LETS WRITE TO FILE!"
- lock.release()
- with open("urls.txt") as url:
- qq = url.readlines()
- arlen = len(qq)/total_thread
- for i in xrange(total_thread):
- tt = threading.Thread(target=worker, args=(qq[arlen*i:arlen*(i+1)],))
- tt.start()
Advertisement
Add Comment
Please, Sign In to add comment