Python IP改变

use*_*005 6 python selenium

首先,我看到了以下帖子:Selenium Python更改IP,但它对我帮助不大.

所以我现在正在做一个测试网站,我试图制作一个反强制力脚本,我的目标是在5次不良尝试后阻止ip并锁定帐户如果100个不同的ip禁止在帐户上尝试密码,那将使暴力非常困难(唯一的问题是你可以阻止用户登录).

我的问题是,我不知道如何更改IP以及如何找到100个不同的ip(硒文章帮助我了解如何更改IP).

我需要的是要么有一个脚本使用浏览器,并使用网站来更改IP,或加载项,或进行API调用,并从命令提示符执行所有操作,并从代理服务/ vpn发出请求(通过这个我的意思是让我的整个流量在代理下而不仅仅是浏览器).

我曾想过每次使用tor来获得新的ips

Lia*_*iam 5

我最近在 python 2.7 for linux 中编写了这个脚本,它应该非常适合你:

#!/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
Run Code Online (Sandbox Code Playgroud)

在 selenium 中实现这个(我没有测试这段代码!):

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
Run Code Online (Sandbox Code Playgroud)