吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 7291|回复: 12
收起左侧

[Python 转载] 基于百度地图API的ip地址查询

  [复制链接]
doctor66 发表于 2017-12-5 17:26

说明:使用ip地址查询太麻烦,偶然搜索发现有人已经写过基于百度API的ip地址查询,这个是前人的结晶,我只是修改了一些,勿喷。
用的python2.7,编码问题真是坑。
百度mapAPI私钥申请:https://jingyan.baidu.com/article/e73e26c0b5b75124adb6a786.html
因为是浏览器访问,因此私钥申请写浏览器模式。
欢迎大家吐槽,有更好的可以分享学习。

# -*- coding:utf-8 -*-
# ip精确查找
import requests 
import json
import sys
reload(sys)
sys.setdefaultencoding('utf8')
ip="目的IP"
AK="你的私钥"
def findip():
    pois=""
    url='https://api.map.baidu.com/location/ip?ip='+ip+'&ak='+AK+'&coor=bd09ll'
    s=requests.get(url)
    page_json=s.text
    #page_json=page_json.decode("unicode_escape")
    #print page_json
    data_dic = json.loads(page_json)
    if(data_dic.has_key("address")):
        country=data_dic["address"]
        print "该IP地址country为:" +country
    else:
        print "查询失败"
    if(data_dic.has_key("content")):
        content=data_dic["content"]
        #print content
        address_component=content["address"]
        #print address_component
        formatted_address=content["address_detail"]
        point=content["point"]
        city=formatted_address["city"]
        district=formatted_address["district"]
        street=formatted_address["street"]
        street_number=formatted_address["street_number"]
        x=point["x"]
        y=point["y"]
        print "该IP地址的具体位置为:" +address_component+district+street+street_number
        print "该IP的所在城市为:"+city
        print "该IP经纬度为:"+x+","+y
    else:
        print 'IP地址定位失败!!!'
findip()

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

NoDocCat 发表于 2017-12-6 22:05
kolar 发表于 2017-12-6 14:42
ip地址查询还是用老高的比较准。

确实, 他家的IP库是最全的, 好多公司在用他家的IP库
kolar 发表于 2017-12-11 22:26
NoDocCat 发表于 2017-12-6 22:05
确实, 他家的IP库是最全的, 好多公司在用他家的IP库

嗯,人家是专业做这个的,靠谱。
愚无尽 发表于 2017-12-5 17:41
蓦留 发表于 2017-12-5 17:49
这方法不是死了么   复活了?
xyz1125 发表于 2017-12-5 18:36
这方法不是死了么   又复活了?
crazykevinz 发表于 2017-12-5 18:59
这是非高精查询    所以你知道的    结果不是你想要的
aroty 发表于 2017-12-5 19:16
数据没那么精准,我还是比较喜欢ipip
kolar 发表于 2017-12-6 14:42
ip地址查询还是用老高的比较准。
自媒体 发表于 2018-1-14 09:25
什么情况?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-6-1 23:48

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表