vendredi 29 mars 2019

Download File using python script behind corporate proxy

I am putting together a script that will download a file from the web .... However some ppl sit being a corporate firewall so this means that if you are @ home the below code works but if you are in the office it hangs unless you set proxy variable manually and then run ....

What I am thinking is create an if statement ... The if statement will check the users IP address and if they user has an IP address in the 8.x or 9.x or 7.x then use this proxy ... Otherwise ignore and proceed with download

The code I am using for this download is below ... I am pretty new to this so i am not sure how to do an if statement for the IP and then use proxy piece so any help would be great

import urllib.request
import shutil
import subprocess
import os
from os import system

url = "https://downloads.com/App.exe"
output_file = "C:\\User\\Downloads\\App.exe"
with urllib.request.urlopen(url) as response, open(output_file, 'wb') as out_file:
    shutil.copyfileobj(response, out_file)


Aucun commentaire:

Enregistrer un commentaire