83

神探Python程序员,带你千里捉小三!(附详情代码)

 4 years ago
source link: http://mp.weixin.qq.com/s?__biz=MzIzNTg3MDQyMQ%3D%3D&%3Bmid=2247486059&%3Bidx=1&%3Bsn=5d3f3a3906edfc83423dbad1295e0bc0
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

2e6zm2J.jpg!web

程序员的隐秘

大家好我是小P

在众人眼中,我是一名Python程序员。

但其实我还有个不为人知的身份, 私家侦探

今天,我接到了一份委托….

vUZvaa3.jpg!web一份委托

通过委托人的述说,专门查了一下深圳最近的天气,保持在10-20度之间,带 羽绒服 的动作确实有些匪夷所思。 因为只是怀疑不能直白的查岗,该如何默默地私下调查呢? 在和委托人深入探讨时,看到她老公发了一张汉庭酒店的入住照片。 然而汉庭酒店在全国都有分店,也不能说明什么啊!

ai6b2qF.jpg!web

突然我灵机一动,也许这一张足以成为是否出轨的证据了! 在委托人疑惑中,我让她把这张照片发到了我的电脑上,经过我飞速的代码编写,真想就此浮出水面!

rUrmyu2.png!web图片信息查询

通过解析照片,获取到了照片的详细与经纬度,在通过经纬度逆推,得到了最终的拍摄地理位置: 陕西省西安市碑林区含光北路162号 ,拿起手机搜索了一下这个地址实锤了,汉庭酒店无疑!

mm2YZnZ.png!web

委托人的连夜机票,最终完成了千里捉小三的壮举! 全剧终…

3EbMjqI.gif

获取地理位置

故事到这里结束了,但是小P侦探是如何通过代码解析到照片中的具体位置呢? 如果人人都可以通过照片解析他人的位置,岂不是乱了套了! 别急,想通过代码解析微信发送的照片地理位置,需要满足以下几点要求:

  1. 他人通过选择原图的方式,发送照片

  2. 相机拍照时,默认设置了GPS定位

  3. 非iphone手机(iphone的地理位置,不会保存在照片中)

现在的手机在拍照时,默认都是打开GPS地位的。 那么你只需要确认对方手机不是iphone的,然后让他给你发送原图就OK了。

照片属性中保存了经纬度,可我们如何能通过经纬度逆推地理位置呢?

此时我们需要使用到百度地图的逆地理编码工具:

BVRBf2m.png!web百度地图逆地理编码

接口很简单,我们简单注册后,创建一个针对地理位置解析的应用即可:

3AvEjae.png!web 小P侦探的代码 说了这么多 ,最终的逆天 代码发布出来,让 大家也和小P侦探一样,圆个福尔摩斯的梦吧!
# -*- coding: utf-8 -*-
# @Author   : 王翔
# @微信号   : King_Uranus
# @公众号    : 清风Python
# @GitHub   : https://github.com/BreezePython
# @Date     : 2019/12/3 23:33
# @Software : PyCharm
# @version  :Python 3.7.3
# @File     : Meetlove.py

import requests
import exifread


class GetPhotoInfo:
    def __init__(self, photo):
        self.photo = photo
        # 百度地图ak
        self.ak = 'nYPs4LQ9a4VhVxj55AD69K6zgsRy9o4z'
        self.location = self.get_photo_info()

    def get_photo_info(self, ):
        with open(self.photo, 'rb') as f:
            tags = exifread.process_file(f)
        try:
            # 打印照片其中一些信息
            print('拍摄时间:', tags['EXIF DateTimeOriginal'])
            print('照相机制造商:', tags['Image Make'])
            print('照相机型号:', tags['Image Model'])
            print('照片尺寸:', tags['EXIF ExifImageWidth'], tags['EXIF ExifImageLength'])
            # 纬度
            lat_ref = tags["GPS GPSLatitudeRef"].printable
            lat = tags["GPS GPSLatitude"].printable[1:-1].replace(" ", "").replace("/", ",").split(",")
            lat = float(lat[0]) + float(lat[1]) / 60 + float(lat[2]) / float(lat[3]) / 3600
            if lat_ref != "N":
                lat = lat * (-1)
            # 经度
            lon_ref = tags["GPS GPSLongitudeRef"].printable
            lon = tags["GPS GPSLongitude"].printable[1:-1].replace(" ", "").replace("/", ",").split(",")
            lon = float(lon[0]) + float(lon[1]) / 60 + float(lon[2]) / float(lon[3]) / 3600
            if lon_ref != "E":
                lon = lon * (-1)
        except KeyError:
            return "ERROR:请确保照片包含经纬度等EXIF信息。"
        else:
            print("经纬度:", lat, lon)
            return lat, lon

    def get_location(self):
        url = 'http://api.map.baidu.com/reverse_geocoding/v3/?ak={}&output=json' \
              '&coordtype=wgs84ll&location={},{}'.format(self.ak, *self.location)
        response = requests.get(url).json()
        status = response['status']
        if status == 0:
            address = response['result']['formatted_address']
            print('详细地址:', address)
        else:
            print('baidu_map error')


if __name__ == '__main__':
    Main = GetPhotoInfo('微信图片_20191203180732.jpg')
    Main.get_location()

网络安全不容忽视

通过这篇文章,大家也需要对网络安全有所警惕了! 不要随便发送原图给你不熟悉的人,如需发送可以在照片中进行相关的编辑打码等操作,这样可以去除照片的地理位置信息。 另外,朋友圈发布的图片,微信都做了转码处理,不用担心这点。

觉得有趣,点个在看呗!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK