Python 提取图片中的GPS信息
生活随笔
收集整理的這篇文章主要介紹了
Python 提取图片中的GPS信息
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
JPG圖片中默認存在敏感數據,例如位置,相機類型等,可以使用Python腳本提取出來,加以利用,自己手動拍攝一張照片,然后就能解析出這些敏感數據了,對于滲透測試信息搜索有一定幫助,但有些相機默認會抹除這些參數。
提取圖片EXIF參數: 通過提取指定圖片的EXIF參數結合GPS數據定位到當時拍攝圖片的物理位置.
import os,sys,json import exifread import urllib.request#調用百度地圖API通過經緯度獲取位置 def getlocation(lat,lon): url = "http://api.map.baidu.com/reverse_geocoding/v3/?ak=GPqF0q0uFT4zOmVKmPU7 \gu3SmB9z3jFV&output=json&coordtype=wgs84ll&location="+lat+","+lonreq = urllib.request.urlopen(url)res = req.read().decode("utf-8")string = json.loads(res)jsonResult = string.get("result")formatted_address = jsonResult.get("formatted_address")print("目標所在城市: {}".format(formatted_address))if __name__ == "__main__":if len(sys.argv) < 2:print("[-] 請傳遞一個圖片地址")else:ImageName = str(sys.argv[1])with open(ImageName,'rb') as f:tags = exifread.process_file(f)print("設備品牌: {}".format(tags['Image Make']))print("具體型號: {}".format(tags['Image Model']))print('照片尺寸: {} x {}'.format(tags['EXIF ExifImageWidth'], tags['EXIF ExifImageLength']))print("創建日期: {}".format(tags['Image DateTime']))print("拍攝時間: {}".format(tags["EXIF DateTimeOriginal"].printable))print("GPS處理方法: {}".format(tags['GPS GPSProcessingMethod']))print("GPSTimeStamp: {}".format(tags['GPS GPSTimeStamp']))print("拍攝軟件版本: {}".format(tags['Image Software']))#緯度LatRef=tags["GPS GPSLatitudeRef"].printableLat=tags["GPS GPSLatitude"].printable[1:-1].replace(" ","").replace("/",",").split(",")Lat=float(Lat[0])+float(Lat[1])/60+float(Lat[2])/float(Lat[3])/3600if LatRef != "N":Lat=Lat*(-1)#經度LonRef=tags["GPS GPSLongitudeRef"].printableLon=tags["GPS GPSLongitude"].printable[1:-1].replace(" ","").replace("/",",").split(",")Lon=float(Lon[0])+float(Lon[1])/60+float(Lon[2])/float(Lon[3])/3600if LonRef!="E":Lon=Lon*(-1)f.close()print("目標所在經緯度: {},{}".format(Lat,Lon))getlocation(str(Lat),str(Lon))將圖片轉為字符圖片: 通過pillow圖片處理庫,對圖片進行掃描,然后用特殊字符替換圖片的每一個位,生成的字符圖片.
from PIL import Image import argparse# 將256灰度平均映射到70個字符上 def get_char(r,g,b,alpha = 256):ascii_char = list("~!@#$%^&*()_+ ")if alpha == 0:return " "length = len(ascii_char)gray = int(0.2126 * r + 0.7152 * g + 0.0722 * b)unit = (256.0 + 1)/lengthreturn ascii_char[int(gray/unit)]if __name__ == "__main__":parser = argparse.ArgumentParser()parser.add_argument("--file",dest="file",help="指定一個圖片文件")parser.add_argument("--width",dest="width",type=int,default=50,help="指定圖片寬度")parser.add_argument("--height",dest="height",type=int,default=25,help="指定圖片高度")args = parser.parse_args()# 使用方式: pip install pillow | main.py --file=xxx.jpgif args.file != None:img = Image.open(args.file)img = img.resize((args.width,args.height), Image.NEAREST)txt = ""for row in range(args.height):for cow in range(args.width):txt += get_char(*img.getpixel((cow,row)))txt += "\n"print(txt)else:parser.print_help()總結
以上是生活随笔為你收集整理的Python 提取图片中的GPS信息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HANA S/4 标准表(MARC M
- 下一篇: 修炼内功想走捷径