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 ...
随机推荐
- js/jquery禁止页面回退
$(function() { //防止页面后退 history.pushState(null, null, document.URL); window.addEventListener('popsta ...
- VUE的语法笔记
v-model = 'content' {{contents}} //vue 双向视图的绑定 v-text 只能返回一个文本内容 v-html 不仅可以返回文本内容还可以返回html标签 v-for ...
- Oracle11.2.0.1 升级Oracle11.2.0.4 后 listener 的端口改变需要处理
1. 因为Oracle采取了异地升级 发现 Oracle的端口号发生了变化: 2. 如果之前的连接还需要用的话 需要禁用 dbhome1 里面的监听 只打开dbhome2的监听 并且修改 监听的端口号 ...
- SQLserver 一种简单的GUI方式创建DBlink copy 表数据的方法
1. 在sqlserver 上面使用GUI的方式创建dblink 首先打开查询分析器 在如下的位置处右键 -新建连接服务器 输入需要copy数据的服务器 输入ip地址 然后建立连接 在打开查询分析器进 ...
- [转帖]linux 内存管理——内核的shmall 和shmmax 参数
(转)linux 内存管理——内核的shmall 和shmmax 参数 内核的 shmall 和 shmmax 参数 SHMMAX= 配置了最大的内存segment的大小 ------>这个 ...
- [代码]--C#action和func的使用
以前我都是通过定义一个delegate来写委托的,但是最近看一些外国人写的源码都是用action和func方式来写,当时感觉对这很陌生所以看起源码也觉得陌生,所以我就花费时间来学习下这两种方式,然后发 ...
- python 模块之-re
就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节码,然后由用 C 编写的匹 ...
- docker --alpine包管理工具 --apk
Alpine中软件安装包的名字可能会与其他发行版有所不同,可以在https://pkgs.alpinelinux.org/packages网站搜索并确定安装包的名称.如果需要的安装包不在主索引内,但是 ...
- Django-website 程序案例系列-18 多表跨表操作优化
详解Django的 select_related 和 prefetch_related 函数对 QuerySet 查询的优化 在数据库有外键的时候,使用 select_related() 和 pref ...
- VMware下Mac系统自适应屏幕
1.下载VMwareTool工具镜像 链接:https://pan.baidu.com/s/1gvXBdzrwYyOEl6yhJurUig 提取码:s1po 2.打开Mac系统,推出DVD 2.设置连 ...