python requests指定出口ip的例子

爬虫需要,一个机器多个口,一个口多个ip,为轮询这些ip

demo

#coding=utf-8
import requests,sys,socket
from requests_toolbelt.adapters import source
reload(sys)
sys.setdefaultencoding('utf-8')

s = requests.Session()
new_source = source.SourceAddressAdapter('192.168.4.2')
s.mount('http://', new_source)
s.mount('https://', new_source)
print s.get('http://xxx.xxx.xxx.xxx:8091/')

需要安装第三方模块requests_toolbelt

pip install requests_toolbelt

Done

以上这篇python requests指定出口ip的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • python3 requests中使用ip代理池随机生成ip的实例

    啥也不说了,直接上代码吧! # encoding:utf-8 import requests # 导入requests模块用于访问测试自己的ip import random pro = ['1.119.129.2:8080', '115.174.66.148', '113.200.214.164'] # 在(http://www.xicidaili.com/wt/)上面收集的ip用于测试 # 没有使用字典的原因是 因为字典中的键是唯一的 http 和https 只能存在一个 所以不建议使用字典

  • Python requests库用法实例详解

    本文实例讲述了Python requests库用法.分享给大家供大家参考,具体如下: requests是Python中一个第三方库,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTTP 测试需求.接下来将记录一下requests的使用: 安装 要使用requests库必须先要安装: pip install requests 创建请求 通过requests库发出一个请求非常简单,首先我们先导入

  • python requests 测试代理ip是否生效

    代码如下所示: import requests '''代理IP地址(高匿)''' proxy = { 'http': 'http://117.85.105.170:808', 'https': 'https://117.85.105.170:808' } '''head 信息''' head = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.

  • Python实现ping指定IP的示例

    贴代码: import os import sys iplist = list() ip = '192.168.1.11' # ip = '172.24.186.191' ip = 'www.baidu.com' backinfo = os.system('ping -c 1 -w 1 %s'%ip) # 实现pingIP地址的功能,-c1指发送报文一次,-w1指等待1秒 print 'backinfo' print backinfo print type(backinfo) if backin

  • python中requests使用代理proxies方法介绍

    学习网络爬虫难免遇到使用代理的情况,下面介绍一下如何使用requests设置代理: 如果需要使用代理,你可以通过为任意请求方法提供 proxies 参数来配置单个请求: import requests proxies = { "http": "http://10.10.1.10:3128", "https": "http://10.10.1.10:1080", } requests.get("http://examp

  • python requests指定出口ip的例子

    爬虫需要,一个机器多个口,一个口多个ip,为轮询这些ip demo #coding=utf-8 import requests,sys,socket from requests_toolbelt.adapters import source reload(sys) sys.setdefaultencoding('utf-8') s = requests.Session() new_source = source.SourceAddressAdapter('192.168.4.2') s.moun

  • python实现扫描局域网指定网段ip的方法

    一.问题由来 工作的局域网中,会接入很多设备,机器人上的网络设备就2个了,一个巨哥红外,一个海康可见光.机器人还有自身的ip. 有时候机器人挂的多了,设备维修更换中,搞来搞去就不记得ip是什么,用自带的软件的确能扫出来,但是这就要开两个windows环境下的软件,耗时耗力,折腾.正好在linux,那简单,敲命令. nmap -P 192.168.1.0/24 可以扫描出 192.168.1.0~192.168.1.255的全部ip 但是前提是要装过nmap apt-get install nma

  • Python使用指定端口进行http请求的例子

    使用requests库 class SourcePortAdapter(HTTPAdapter): """"Transport adapter" that allows us to set the source port.""" def __init__(self, port, *args, **kwargs): self.poolmanager = None self._source_port = port super().

  • python requests使用socks5的例子

    网络爬虫由于一个ip频繁访问同一网站,容易返回456或者被长时间封禁. 特别的本机有socks5客户端的设置如下,前提是已经安装了socks5的客户端软件,并且启动起来在固定端口为本机提供服务. 使用前先更新requests版本为支持socks的版本. pip install -U requests[socks] import requests my_proxies={"http":"http://127.0.0.1:1080","https":

  • python requests更换代理适用于IP频率限制的方法

    有些网址具有IP限制,比如同一个IP一天只能点赞一次. 解决方法就是更换代理IP. 从哪里获得成千上万的IP呢? 百度"http代理" 可获得一大堆网站. 比如某代理网站,1天6元,可以无限提取. 把提取的IP,保存到txt文件中. 写一个方法,读取文件,存入数组中 def getProxysFromFile(): with open("proxy.txt", "r") as f: l = f.readlines() return l 比如执行某

  • python实现指定ip端口扫描方式

    在Linux中判断一台主机是否可达,可以使用ping命令,而判断端口是否打开,可以使用telnet命令,但是telnet命令没有超时时间的参数,使用起来不是很方便,那么可以利用Python来完成一个端口扫描的功能 socket实现端口扫描 #!/usr/bin/env python import socket def get_ip_status(ip,port): server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: se

  • python 穷举指定长度的密码例子

    本程序可根据给定的字符字典,穷举指定长度的所有字符串: def get_pwd(str, num): if(num == 1): for x in str: yield x else: for x in str: for y in get_pwd(str, num-1): yield x+y strKey="abc" for x in get_pwd(strKey,3): print x 结果: aaa aab aac aba abb abc aca acb acc baa bab b

  • Python获取指定网段正在使用的IP

    #!/usr/bin/env python # -*- coding: utf-8 -*- ''''' 使用方法样例 python test20.py 192.168.1.1 (会扫描192.168.1.1-255的ip) 多线程加速后大概十几秒 ''' import platform import sys import os import time import threading live_ip = 0 def get_os(): os = platform.system() if os =

  • Python实现自动访问网页的例子

    我就废话不多说了,直接上代码吧! import urllib.request import requests import time import ssl import random def openUrl(ip, agent): headers = {'User-Agent': agent} proxies = {'http' : ip} requests.get("https://www.baidu.com", headers=headers, proxies=proxies, v

随机推荐