Advertisement
Guest User

Untitled

a guest
Oct 27th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. require 'net/http'
  2. require 'mysql2'
  3. require_relative 'thread_pool.rb'
  4.  
  5. ##########################################################################
  6. #
  7. # Checks if all proxies marked working in database are actually working
  8. #
  9. # Multithreaded to 10 threads at once using thread pool with worker queue
  10. # and Mutex locks to ensure 1 thread per worker block
  11. #
  12. ##########################################################################
  13.  
  14. def proxy_checker()
  15. ######## First let's connect to that sexy ass MySQL database ##############
  16. $proxy_database = Mysql2::Client.new(:host => 'localhost', :username => 'carpanda', :password => 'alexcarpanda')
  17. $proxy_database.query("USE proxy_database")
  18.  
  19. #CREATE TABLE proxy_table (id INTEGER PRIMARY KEY NOT NULL, ip TEXT, port TEXT, alive_boolean BOOL);
  20. #inet_aton and inet_ntoa to convert ip to integer
  21. if $proxy_database
  22. puts "Successfully connected to proxy database"
  23. else
  24. puts "Bad connection to proxy databse, exiting..."
  25. return
  26. end
  27.  
  28. ############## Define a single proxy checking instance that checks a few proxies at once ###########
  29. def proxy_checking_instance(ip, port)
  30. #puts "Checking #{ip}:#{port}"
  31. attempt = 1
  32. begin
  33. Net::HTTP::Proxy(ip, port).start('makeabank.com') { |http|
  34. response = http.request_get('/faq.cgi');
  35. response.body.split(/\n/).each do |line|
  36. if (line.index('AnonyLevel')) then print "GOOD PROXY: ",ip,":",port,"\n\n" end
  37. end
  38. }
  39. rescue Errno::ECONNREFUSED
  40. puts "connection refused (attempt ##{attempt})"
  41. if attempt < 3 then
  42. attempt+=1
  43. retry
  44. end
  45. rescue
  46. print "BAD PROXY: ",ip,":",port,"\n\n"
  47. $proxy_database.query("UPDATE proxy_table SET alive_boolean=0 WHERE id=inet_aton('#{ip}')")
  48. end
  49. end
  50.  
  51. ############## Setup Threads for concurrent proxy checking #######################
  52. proxy_thread_pool = ThreadPool.new(10)
  53.  
  54. proxyList = $proxy_database.query("SELECT * FROM proxy_table where alive_boolean=true")
  55. proxyList.each do |proxy|
  56. print "Currently checking: ", proxy['ip'],"\n"
  57. proxy_thread_pool.process{proxy_checking_instance(proxy['ip'],proxy['port'])}
  58. end
  59. proxy_thread_pool.join()
  60. end
  61.  
  62. proxy_checker()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement