Last active
January 2, 2019 15:33
-
-
Save spookyahell/ae38a2a349965c11c27627162d783212 to your computer and use it in GitHub Desktop.
tracking exe version online (with ETag)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pefile | |
import pprint | |
def get_version_info(file): | |
pe = pefile.PE(file) | |
string_version_info = {} | |
for fileinfo in pe.FileInfo[0]: | |
if fileinfo.Key.decode() == 'StringFileInfo': | |
for st in fileinfo.StringTable: | |
for entry in st.entries.items(): | |
string_version_info[entry[0].decode()] = entry[1].decode() | |
return string_version_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from peinfo import get_version_info | |
from time import strftime, sleep | |
exe_link = '' | |
# Example: https://telerik-fiddler.s3.amazonaws.com/fiddler/FiddlerSetup.exe | |
r = requests.get(exe_link) | |
with open('TheFile.exe','wb') as f: | |
f.write(r.content) | |
vi = get_version_info('TheFile.exe') | |
pv = vi['ProductVersion'] | |
print(f'Starting with version {pv}') | |
ETag = r.headers.get('ETag') | |
r = requests.get(exe_link, headers = {'If-None-Match':ETag}) | |
while r.status_code == 304: | |
r = requests.get(exe_link, headers = {'If-None-Match':ETag}) | |
print(strftime(f'%T - {r.status_code}')) | |
sleep(60) | |
if r.status_code == 200: | |
with open('TheFile.exe','wb') as f: | |
f.write(r.content) | |
vi = get_version_info('TheFile.exe') | |
pv = vi['ProductVersion'] | |
print(f'Update to version {pv} available / published') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not so hard to modify this to work if the server with the file does not return an ETag in the response headers, but in that case it's even more important to increase the sleeping time to avoid loading the file from the server to often,
if I personally ever find the need to create a script without the ETag header, I will also upload it here and then add a link here