Skip to content

Instantly share code, notes, and snippets.

@spookyahell
Last active January 2, 2019 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spookyahell/ae38a2a349965c11c27627162d783212 to your computer and use it in GitHub Desktop.
Save spookyahell/ae38a2a349965c11c27627162d783212 to your computer and use it in GitHub Desktop.
tracking exe version online (with ETag)
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
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')
@spookyahell
Copy link
Author

spookyahell commented Jan 2, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment