Changing Python IP Address

First of all, I saw the following message: Selenium Python Changing the IP , but it didn’t help me much.

So, I am currently doing a test site and I am trying to make a script effort multiple times, my goal is to block the ip after 5 failed attempts and lock the account if 100 different ip prohibit password attempts on the account, which would make brute force very difficult (the only problem would be that you could prevent the user from logging in).

My problem is that I don’t have a hint on how to change ip and how to find 100 different ip (selenium article helped me understand a little how to change ip).

I needed to either have a script, working with the browser, and using the website to change ip, or add-on, or to call the API and execute everything from the command line, and asking to send a request from the proxy service / vpn (under this I I mean that all my traffic under a proxy is not only a browser).

I thought about using tor to get new ips every time

+6
source share
2 answers

I recently wrote this script in python 2.7 for linux, which should work just fine for you:

#!/usr/bin/env python

import requests
from os import system

proxies = {'http':  'socks5://127.0.0.1:9050',
           'https': 'socks5://127.0.0.1:9050'}

for x in range(100):
  session = requests.session()
  session.proxies = proxies
  print session.get("http://httpbin.org/ip").text
  system("sudo service tor reload") #sudo apt-get install tor

to implement this in selenium (I have not tested this code!):

from selenium import webdriver

def change_proxy(proxy,port):
    profile = webdriver.FirefoxProfile();
    profile.set_preference("network.proxy.type", 1);
    profile.set_preference("network.proxy.http", proxy);
    profile.set_preference("network.proxy.http_port", port);
    profile.set_preference("network.proxy.ssl", proxy);
    profile.set_preference("network.proxy.ssl_port", port);
    driver = webdriver.Firefox(profile);
    return driver
+2
source

, , , script. IP- , IP-, . , , 100 IP- . , :

  • - ( ), , , IP-. , , IP. / script - , IP-.

  • / script. - , , HTTP_FAKE_IP, IP , IP- . - , HTTP-, .

  • 100 ( ) IP- , IP- /.

  • , IP.

, , - , IP. , , . IP- IP-, 100 IP-, . , , .

+1

Source: https://habr.com/ru/post/1016899/


All Articles