ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!

Cracked.to | Best Cracking Forum Around | Free Premium Accounts




 1586

[sunjester tuts] Proxy Rotation with Python

by sunjester - 1 year ago
This post is by a banned member (sunjester) - Unhide
sunjester  
Registered
0
Rep
42
Likes
Posts: 19
Threads: 12
Joined: Mar 2019
Vouches: 0
Credits: 5.510
Introduction
All of my tutorials are written in a unix environment. If you are using Kali, perfect. I am using Debian (xenial). If you have any errors, post them here and I'll see what I can do. You will need Python and probably will need the requests library installed.
 
Requests
You can install the requests library with pip
Code:
pip install requests
and you can import the library using the import keyword.
Code:
#!/usr/bin/env python
import requests
Proxies
Using a proxy with the requests library is easy.
Code:
#!/usr/bin/env python
import requests

proxies = {
        "socks5": "67.205.174.209:1080"
}

s = requests.get("https://api.ipify.org", proxies=proxies)
print s.content
Rotation
The theory here is that you "rotate" through proxies as you make requests. You could randomly select a proxy from the array or even do it by timeout. The most simple way is to just iterate through the array as you make the requests, by default, I believe that is what the the requests lib does already. So let's pick a random one.
Code:
#!/usr/bin/env python
import requests, random, os

proxies = [
        "163.172.220.221:8888",
        "138.68.41.90:3128"
]

proxy = random.choice(proxies)
os.environ['HTTP_PROXY'] = proxy

s = requests.get("https://api.ipify.org")
print s.content
The script above uses the random library to pick a random one from the array and then uses the os library to set an environment variable to the proxy we randomly selected.
This post is by a banned member (nsarat) - Unhide
nsarat  
Registered
0
Rep
5
Likes
Posts: 4
Threads: 0
Joined: Mar 2019
Vouches: 0
Credits: -4
#2
this is perfect for what i need
This post is by a banned member (socalgurl) - Unhide
socalgurl  
Registered
0
Rep
10
Likes
Posts: 10
Threads: 0
Joined: Mar 2019
Vouches: 0
Credits: 0
#3
thanks for this
This post is by a banned member (RaresMTH) - Unhide

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)