Free Proxy Program in Ruby
Hi , This new post is in ruby. This program provide you free proxy in a sqlite database for free. Run this program and get free proxy in your sqite db.
The program accept three commands from command line:
1. load :load all the available proxy from website "whatismyip.com"
2. validate : validates the proxy is working or not.
3. delete : delete the proxy from the database which are not working.
run it as : ruby progname load
require 'httparty'
require 'sqlite3'
require 'parallel'
require 'nokogiri'
require 'open-uri'
functionCall=ARGV[0]
module Name
class Me
include HTTParty
base_uri 'http://www.whatismyip.com/'
def initialize()
end
def testproxy(ip, port)
self.class.http_proxy ip, port
begin
resp = self.class.get("/")
if resp.include? "Your IP:"
puts resp
return 1
else
return 3
end
rescue Exception => e
end
return 2
end
def validate
db = SQLite3::Database.new("proxy.db")
begin
values = db.prepare "Select * from proxyTable"
result = values.execute
proxylist = Array.new
while(re = result.next)do
@IP = re[1],re[2].to_s()
proxylist.push @IP
end
ensure
values.close if values
end
Parallel.each(proxylist, :in_threads=>10, :in_processes=>1) do |proxy|
x = Name::Me.new()
response = x.testproxy(proxy[0], proxy[1])
db.execute "UPDATE proxyTable set status = " + response.to_s() + " where IP ='"+ proxy[0] +"' and port = '" +proxy[1] + "'"
puts "Tested proxy - " + proxy[0] + ":" + proxy[1] + ". Response Code = " + response.to_s()
end
db.close if db
end
def load
db = SQLite3::Database.new("proxy.db")
doc = Nokogiri::HTML(open("http://free-proxy-list.net/"))
@IP = doc.xpath("//table[@id='proxylisttable']//tbody/tr")
print @IP.length
x=0
for i in @IP do
ip=i.xpath("td[1]/text()")
port=i.xpath("td[2]/text()")
print ip.to_s()+":"+port.to_s()
print("\n")
print (x+=1)
print "\n"
begin
db.execute "CREATE TABLE IF NOT EXISTS proxyTable( id INTEGER PRIMARY KEY, IP VARCHAR, Port INT,Type VARCHAR,Status INT)"
db.execute "INSERT INTO proxyTable (IP, Port, Type, Status) VALUES('"+ip.to_s()+"',"+port.to_s()+",'HTTP','0')"
rescue SQLite3::Exception => e
puts "Exception occured"
puts e
end
end
db.close if db
end
def delete
db = SQLite3::Database.new("proxy.db")
db.execute "DELETE FROM proxyTable where Status = 3"
puts("Action is compeleted")
db.close if db
end
end
end
def run(functionCall)
x = Name::Me.new()
if functionCall=='validate'
x.validate()
elsif functionCall=='load'
x.load()
elsif functionCall=='delete'
x.delete()
else
puts "enter a valid command"
end
end
run(functionCall)
The program accept three commands from command line:
1. load :load all the available proxy from website "whatismyip.com"
2. validate : validates the proxy is working or not.
3. delete : delete the proxy from the database which are not working.
run it as : ruby progname load
require 'httparty'
require 'sqlite3'
require 'parallel'
require 'nokogiri'
require 'open-uri'
functionCall=ARGV[0]
module Name
class Me
include HTTParty
base_uri 'http://www.whatismyip.com/'
def initialize()
end
def testproxy(ip, port)
self.class.http_proxy ip, port
begin
resp = self.class.get("/")
if resp.include? "Your IP:"
puts resp
return 1
else
return 3
end
rescue Exception => e
end
return 2
end
def validate
db = SQLite3::Database.new("proxy.db")
begin
values = db.prepare "Select * from proxyTable"
result = values.execute
proxylist = Array.new
while(re = result.next)do
@IP = re[1],re[2].to_s()
proxylist.push @IP
end
ensure
values.close if values
end
Parallel.each(proxylist, :in_threads=>10, :in_processes=>1) do |proxy|
x = Name::Me.new()
response = x.testproxy(proxy[0], proxy[1])
db.execute "UPDATE proxyTable set status = " + response.to_s() + " where IP ='"+ proxy[0] +"' and port = '" +proxy[1] + "'"
puts "Tested proxy - " + proxy[0] + ":" + proxy[1] + ". Response Code = " + response.to_s()
end
db.close if db
end
def load
db = SQLite3::Database.new("proxy.db")
doc = Nokogiri::HTML(open("http://free-proxy-list.net/"))
@IP = doc.xpath("//table[@id='proxylisttable']//tbody/tr")
print @IP.length
x=0
for i in @IP do
ip=i.xpath("td[1]/text()")
port=i.xpath("td[2]/text()")
print ip.to_s()+":"+port.to_s()
print("\n")
print (x+=1)
print "\n"
begin
db.execute "CREATE TABLE IF NOT EXISTS proxyTable( id INTEGER PRIMARY KEY, IP VARCHAR, Port INT,Type VARCHAR,Status INT)"
db.execute "INSERT INTO proxyTable (IP, Port, Type, Status) VALUES('"+ip.to_s()+"',"+port.to_s()+",'HTTP','0')"
rescue SQLite3::Exception => e
puts "Exception occured"
puts e
end
end
db.close if db
end
def delete
db = SQLite3::Database.new("proxy.db")
db.execute "DELETE FROM proxyTable where Status = 3"
puts("Action is compeleted")
db.close if db
end
end
end
def run(functionCall)
x = Name::Me.new()
if functionCall=='validate'
x.validate()
elsif functionCall=='load'
x.load()
elsif functionCall=='delete'
x.delete()
else
puts "enter a valid command"
end
end
run(functionCall)