У меня есть следующее решение, и оно работает (в корпоративной среде)
import win32com.client
try:
import _winreg as winreg
except:
import winreg
class HTTP:
proxy = ""
isProxy = False
def __init__(self):
self.get_proxy()
def get_proxy(self):
oReg = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
oKey = winreg.OpenKey(oReg, r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
dwValue = winreg.QueryValueEx(oKey, 'ProxyEnable')
print('[+] dwValue[0] = '+str(dwValue[0]))
if dwValue[0] == 1:
oKey = winreg.OpenKey(oReg, r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
dwValue = winreg.QueryValueEx(oKey, 'ProxyServer')[0]
print('[+] oKey = '+str(oKey))
print('[+] dwValue = '+str(dwValue))
self.isProxy = True
self.proxy = dwValue
def url_post(self, url, formData):
httpCOM = win32com.client.Dispatch('Msxml2.ServerXMLHTTP.6.0')
if self.isProxy:
print('[+] self.isProxy = true')
httpCOM.setProxy(2, self.proxy, '<local>')
httpCOM.setOption(2, 13056)
httpCOM.Open('POST', url, False)
httpCOM.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
httpCOM.setRequestHeader('User-Agent', 'whatever you want')
httpCOM.send(formData)
return httpCOM.responseText
http = HTTP()
http.url_post('http://bbc.co.uk', 'test=1')
Мой вопрос заключается в том, как я могу перевести то, что у меня есть, чтобы вместо этого использовать t с запросами или urllib
Выходы:
[+] dwValue[0] = 1
[+] oKey = <PyHKEY:0x00000000000000000000148>
[+] dwValue = webproxy.f5.pee2peead.local.9090
[+] self.isProxy = true