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内核设计与实现》第五章学习笔记
<Linux内核设计与实现>第五章学习笔记 姓名:王玮怡 学号:20135116 一.与内核通信 在Linux中,系统调用是用户空间访问内核的唯一手段:除异常和陷入外,它们是内核 ...
- Linux内核分析第六周总结
进程控制块PCB--task_struct 操作系统的内核里的三大功能: 进程管理 内存管理 文件系统 进程描述符--task_struct 进程管理是最核心的内容 然而Linux进程的状态与操作系统 ...
- github学习步骤
组员1: 王文政 201303011159 作业网址 :https://github.com/1246251747/3/blob/master/jjj.txt 心得: 1. 申请gi ...
- Python学习笔记 -- 第四章
高阶函数 变量可以指向函数 f=abs f(-10) 10 变量f指向abs函数,直接调用abs()函数和调用f()完全相同 传入参数 变量可以指向函数,函数的参数可以接收另一个函数的参数,这种函数成 ...
- Linux下数据库备份恢复过程
1. 远程进入Linux服务器. 2. 一般登录的是root用户, 第一步切换到Oracle用户, 命令: su - oracle 3. 查看服务器上面数据库的监听的状况 lsnrctl 之后输入命令 ...
- ELK日志框架(1):安装Elasticsearch组建单服务器多节点集群
ELK简介 最近有个需求搭建一套日志系统用于集成几个业务系统的日志提供快速的检索功能,目前是用Log4net存数据库+Error级别发邮件方式,也算简单暴力好用,但历史日志的模糊查询确实很慢,所以使用 ...
- python之函数(可选参数和混合参数)
代码举例: # 函数可选参数举例,hoppy参数可传可不传 def getinfo(name, age, hoppy=''): if hoppy: print("name:", n ...
- appium学习记录2
unittest 学习 每执行一次 testcase 就会调用一次 setUP 与teardown 类方法只会执行一次 开始 与结束时候执行 类似反射方法 __init__ 与 __del__ set ...
- BZOJ4517[Scoi2016]美味——主席树
题目描述 一家餐厅有 n 道菜,编号 1...n ,大家对第 i 道菜的评价值为 ai(1≤i≤n).有 m 位顾客,第 i 位顾客的期 望值为 bi,而他的偏好值为 xi .因此,第 i 位顾客认为 ...
- PHP页面显示中文字符出现乱码
[出现问题] php页面显示中文字符出现乱码 [解决方法] 在php页面的代码前插入一行代码即可 header("Content-Type: text/html;charset=utf-8& ...