ip更换
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门
https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6EmUbbW&id=564564604865
import requests
import time
import sys
import os.path "List of free ip services"
"http://icanhazip.com/"
"http://checkip.dyndns.org/"
"https://freegeoip.net/json/"
"http://www.telize.com/ip"
"http://ip-api.com/json"
"http://curlmyip.com/"
"http://ipinfo.io/ip" #Global variables
ipFile="/tmp/ip.log"
timeout = 10 class Service:
url=""
def request(self): return requests.get(self.url, timeout = timeout) class Icanhazip(Service):
name="icanhazip"
url="http://icanhazip.com/"
def ip(self): return self.request().text.strip() class Freegeoip(Service):
name="freegeoip"
url="https://freegeoip.net/json/"
def ip(self): return self.request().json()["ip"] class Telize(Service):
name="telize"
url="http://www.telize.com/ip"
def ip(self): return self.request().text.strip() class IpApi(Service):
name="ip-api"
url="http://ip-api.com/json"
def ip(self): return self.request().json()["query"] class Ifconfig(Service):
name="ifconfig.me"
url="http://ifconfig.me/all.json"
def ip(self): return self.request().json()["ip_addr"] def request_ip():
#List of services
services = [Icanhazip(), Freegeoip(), Telize(), IpApi(), Ifconfig() ]
for i in range(len(services)): service = services[i]
try:
start = time.time()
print "* Requesting current ip with '{}'".format(service.name)
ip = service.ip()
print "* Request took {} seconds ".format(int(time.time() - start))
return ip
except Exception as error:
print "* Exception when requesting ip using '{}': {} ".format(service.name, error ) error = "Non available services, add more services or increase the timeout (services = {}, timeout = {}) ".format(len(services), timeout)
raise RuntimeError(error) def current_ip():
return open(ipFile,"r").readlines()[0] def save_ip(ip):
f = open(ipFile,'w')
f.write(str(ip)) #Main
if os.path.isfile(ipFile) : #File exists
request_ip = request_ip()
current_ip = current_ip() if request_ip != current_ip:
save_ip(request_ip)
print "* IP has changed from {} to {}".format(current_ip, request_ip)
sys.exit(1)
else :
print "* IP is still the same: {}".format(current_ip) else:
request_ip = request_ip()
save_ip(request_ip)
print "* This is the first time to run the ip_change script, I will create a file in {} to store your current address: {} ".format(ipFile, request_ip) #Test
"""
services = [Icanhazip(), Freegeoip(), Telize(), IpApi(), Ifconfig() ]
for i in range(len(services)):
service = services[i]
print "{} ip result: {} ".format(service.name, service.ip() )
"""
ip更换的更多相关文章
- 记一次服务器迁移 TFS客户端ip更换
服务器迁移,TFS服务端IP由原10.58.8.231更换至10.58.1.230 TFS客户端更换ip操作比较复杂,请谨慎操作,避免脱库的风险!!! 打开注册表,运行->regedit 找到H ...
- k8s集权IP更换
-.背景描述 背景:在场内进行部署完成后标准版产品,打包服务器到客户现场后服务不能正常使用,因为客户现场的IP地址不能再使用场内的IP,导致部署完的产品环境在客户现场无法使用:此方案就是针对这一问题撰 ...
- Linux下检测IP地址冲突及解决方法
问题说明:在公司办公网内的一台物理机A上安装了linux系统(ip:192.168.9.120),在上面部署了jenkins,redmine,svn程序.由于是在办公网内,这台机器和同事电脑都是在同一 ...
- selenium在scrapy中的使用、UA池、IP池的构建
selenium在scrapy中的使用流程 重写爬虫文件的构造方法__init__,在该方法中使用selenium实例化一个浏览器对象(因为浏览器对象只需要被实例化一次). 重写爬虫文件的closed ...
- Lvs IP负载均衡技术
Lvs集群的通用结构 Lvs集群采用IP负载均衡技术,属于IP层的交换(L4),具有很好的吞吐率.调度器分析客户端到服务器的IP报头信息,将请求均衡地转移到不同的服务器上执行,且调度器自动屏蔽掉服务器 ...
- 腾讯云API弹性公网IP踩坑
由于自己管理的云服务器数量比较多,时不时需要更换IP,在管理台上一下下点击,实在浪费时间,于是就想到了通过API调用的方式,将更换IP一系列动作,全部集成到Python代码里面,实现一行命令,完成IP ...
- 中间件使用之(UA,IP,selenium)的使用
一.UA池:User-Agent池 - 作用:尽可能多的将scrapy工程中的请求伪装成不同类型的浏览器身份. - 操作流程: 1.在下载中间件中拦截请求 2.将拦截到的请求的请求头信息中的UA进行篡 ...
- 网络爬虫一定要用代理IP吗
数据采集现在已经成为大数据时代不可以缺少的一部分,在数据采集过程中,很多人都会用到代理ip,那么网络爬虫一定要用代理IP吗?答案虽然不是肯定的,但出现以下情况一定是需要用到代理IP的.1.在爬虫的时候 ...
- 探索ASP.NET MVC5系列之~~~3.视图篇(下)---包含常用表单和暴力解猜防御
其实任何资料里面的任何知识点都无所谓,都是不重要的,重要的是学习方法,自行摸索的过程(不妥之处欢迎指正) 汇总:http://www.cnblogs.com/dunitian/p/4822808.ht ...
随机推荐
- Linux 第七章学习笔记
1:链接概述 链接(linking)是将各种代码和数据部分收集起来并组合成为一个单一文件的过程,这个文件可被加载(或被拷贝)到存储并执行. 编译系统提供的调用预处理器.编译器.汇编器和链接器来构造目标 ...
- 结对项目gobang
题目介绍:实现五子棋的基本规则,分黑棋和白棋.连成5个的胜利,完成了五子棋的单人游戏. 代码地址:https://github.com/liuxianchen/gobang 结对人:刘仙臣 康佳 结 ...
- The Golden Age CodeForces - 813B (数学+枚举)
Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a ...
- Linux安装的分区问题
对于一般的外部SATA存储设备,在ubuntu中会显示在/etc/sd*中,例如: SATA1插槽上的文件名:/dev/sda SATA5插槽上的文件名:/dev/sdb USB磁盘:/dev/sdc ...
- 彻底弄懂jsonp原理及实现方法
一. 同源策略 所有支持Javascript的浏览器都会使用同源策略这个安全策略.看看百度的解释: 同源策略,它是由Netscape提出的一个著名的安全策略. 现在所有支持JavaScript 的浏览 ...
- Laravel自定义 封装便捷返回Json数据格式引用
一般返回数据格式 return response()->json(['status' => 'success','code' => 200,'message' => '关注成功 ...
- ES next & Async Await
ES next & Async Await https://jestjs.io/docs/en/asynchronous#async-await ES7 new async () => ...
- Python中print/format字符串格式化实例
Python 字符串格式化使用 "字符 %格式1 %格式2 字符"%(变量1,变量2),%格式表示接受变量的类型.简单的使用例子如下 # 例:字符串格式化Name = '17jo' ...
- Java之JSON操作(gson)
使用gson包操作JSON数据. 依赖包:gson-2.8.2.jar <dependency> <groupId>com.google.code.gson</group ...
- AtCoder WTF 2019 C2. Triangular Lamps Hard
题目链接 感觉这样的题真的称得上是鬼斧神工啊,\(\text{OI}\)中能多一些这样的题目就太好了. 题意: 有一个二维的三角坐标系,大概如图所示(图是从atcoder里偷下来的): 坐标系上的每个 ...