-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquickstart.rb
More file actions
30 lines (25 loc) · 1.11 KB
/
Copy pathquickstart.rb
File metadata and controls
30 lines (25 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# QuantumProxies — Ruby quickstart (net/http).
# Rotating residential proxies: new IP per request, sticky sessions, geo-targeting.
# Get credentials at https://quantumproxies.io
require "net/http"
require "json"
require "uri"
USER = "YOUR_USERNAME" # from your dashboard
PASS = "YOUR_PASSWORD"
HOST = "residentialboson.quantumproxies.io"
def through_proxy(port:, user:)
uri = URI("https://ipinfo.io/json")
http = Net::HTTP.new(uri.host, uri.port, HOST, port, user, PASS)
http.use_ssl = true
http.open_timeout = http.read_timeout = 30
JSON.parse(http.get(uri.path).body)
end
# Rotating: new IP on every request (port 9000)
puts "rotating: #{through_proxy(port: 9000, user: USER)["ip"]}"
# Country targeting: append -country-XX to the username
geo = through_proxy(port: 9000, user: "#{USER}-country-fr")
puts "fr exit: #{geo["ip"]} #{geo["country"]}"
# Sticky session: same IP for `lifetime` minutes (port 10000)
sticky = "#{USER}-country-us-session-ab12-lifetime-10"
puts "sticky #1: #{through_proxy(port: 10_000, user: sticky)["ip"]}"
puts "sticky #2: #{through_proxy(port: 10_000, user: sticky)["ip"]}" # same IP