lundi 13 mai 2019

Python - If string in file starts with 16 then

I have a script that checks my ip address on my PC and writes it to a file on my PC - This is working fine

import socket
import sys
import requests
import urllib.request
import shutil
import subprocess
from time import sleep
import os
from os import system

# URL for download
URL = 'https://here/app.exe'

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 1))
local_ip_address = s.getsockname()[0]
sys.stdout = open("C:\\Temp\\nw_check.txt", "w+")
print(s.getsockname() [0])

Now I would like to do this next

Check the file C:\Temp\nw_check.txt and if the IP address in that file starts with 116, 115, 117 then download the above app using a proxy I will set .. If it starts with anything else then proceed with download

if xxxxxx(xxxxxxxx()).startswith(('116', '115', '117')):
    r = requests.get(URL, stream=True, proxies={'http': 'http://proxy:6547', 'https': 'http://proxy:6547'})
else:
    r = requests.get(URL, stream=True)

Aucun commentaire:

Enregistrer un commentaire