Advertisement
Guest User

ProxScan

a guest
Dec 18th, 2011
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.55 KB | None | 0 0
  1. require 'socket'
  2. require 'thread'
  3. require 'net/http'
  4. require 'timeout'
  5.  
  6. threads = []
  7. $timeout = 10
  8. $raw = false
  9.  
  10. class Helper
  11.     def initialize
  12.     end
  13.    
  14.     def Banner
  15.             print("\n\t# Proxygrab 0.2 by Bonkers #\n\n")
  16.     end
  17.    
  18.     def Help
  19.         print("Options:\n\n-t 5    Proxy-Timeout in Seconds\n-r      Raw-Output (IP:Port, sorted by response-time)\n-h      Shows this help\n")
  20.         exit(0)
  21.     end
  22.  
  23.     def Args
  24.         ARGV.each_with_index do |arg, index|
  25.             if arg == "-t"
  26.                 $timeout = ARGV[index + 1]
  27.             elsif arg == "-h"
  28.                 self.Help()
  29.                 exit(0)
  30.             elsif arg == "-r"
  31.                 $raw = true
  32.             end
  33.         end
  34.     end
  35. end
  36.  
  37.  
  38. class Proxgrab
  39.     def initialize
  40.     end
  41.    
  42.     def AntiBotToken
  43.    
  44.         res = Net::HTTP.start('www.proxy-listen.de', 80) {|http|
  45.             http.get('/Proxy/Proxyliste.html')
  46.         }
  47.         if res.body =~ /<input name="z" value="(.+?)"/m
  48.             return $~[1]
  49.         else
  50.             raise "Could not get security-token"
  51.         end
  52.     end
  53.  
  54.     def Grab
  55.         begin
  56.             http = Net::HTTP.new('www.proxy-listen.de', 80)
  57.             data = "filter_port=&filter_http_gateway=&filter_http_anon=&filter_response_time_http=5&z=#{self.AntiBotToken()}&filter_country=US&filter_timeouts1=&liststyle=leech&proxies=300&type=http&submit=Anzeigen"
  58.             resp, data = http.post('/Proxy/Proxyliste.html', data)
  59.             body = resp.body()
  60.             result = body.scan(/<a class="proxyList".+?target="_blank">(.+?):(.+?)<\/a>/m)
  61.             return result
  62.         rescue
  63.             raise "Could not download the proxy-list"
  64.         end
  65.     end
  66. end
  67. class Proxtest
  68.     def initialize
  69.     end
  70.     def Test(ip, port)
  71.         begin
  72.             timeout($timeout.to_i) do
  73.                 start_time = Time.now.to_f
  74.                 client = TCPSocket.new(ip, port)
  75.                 ip_services = [ "GET http://checkip.dyndns.org HTTP/1.1\r\nHost: checkip.dyndns.org\r\nConnection: close\r\n\r\n", "GET http://myip.is HTTP/1.1\r\nHost: myip.is\r\nConnection: close\r\n\r\n" ]
  76.                 client.puts ip_services[rand(2)]
  77.                 answer = client.gets(nil)
  78.                 if answer =~ /(Current|Hostname)/
  79.                     temp = "#{ip}:#{port}"
  80.                     if $raw == true
  81.                         puts(temp)
  82.                     else
  83.                         puts("#{temp}#{" "*(26-temp.length)}OK      #{(Time.now.to_f-start_time).round(2)}")
  84.                     end
  85.                 else
  86.                 end
  87.             end
  88.         rescue Timeout::Error
  89.             exit!
  90.         rescue
  91.         end
  92.     end
  93. end
  94.  
  95. hp = Helper.new
  96. pg = Proxgrab.new
  97.  
  98. hp.Banner()
  99. hp.Args()
  100.  
  101. check_us = pg.Grab()
  102.  
  103. if !$raw
  104.     puts("#{check_us.length} Proxies grabbed. Checking them.\n")
  105.     puts("\nIP:Port#{" "*19}HTTP#{" "*4}Time\n\n")
  106. end
  107. check_us.each do |proxy|
  108.         threads << Thread.new(proxy){ |proxy|
  109.         pt = Proxtest.new
  110.         pt.Test(proxy[0], proxy[1])
  111.         }
  112. end
  113.  
  114. threads.each { |aThread|
  115.                 aThread.join
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement