Created
July 16, 2018 15:04
-
-
Save lawvs/d36cd16683f36e1990538a0d065edf11 to your computer and use it in GitHub Desktop.
check proxy availability
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
#!/usr/bin/env python3 | |
import requests | |
TEST_URL = 'https://www.baidu.com/' | |
def check_proxy(proxyIp, proxyPort='8080', proxyType='https'): | |
if len(proxyIp) <= 0: | |
return False | |
proxy = "{proxyIp}:{proxyPort}".format(proxyIp=proxyIp, proxyPort=proxyPort) | |
try: | |
requests.get( | |
TEST_URL, | |
timeout=10, | |
stream=True, | |
proxies={proxyType:proxy} | |
) | |
except: | |
return False | |
return True | |
def check_proxy_list(proxyList): | |
for proxy in proxyList: | |
protocol = proxy.split('://')[0] | |
proxyURL = proxy.split('://')[1] | |
proxyIp = proxyURL.split(':')[0] | |
proxyPort = proxyURL.split(':')[1] | |
res = check_proxy(proxyIp, proxyPort, protocol) | |
if res: | |
print('success', proxy) | |
else: | |
print('fail', proxy) | |
def main(): | |
proxyList = [ | |
'protocol://exampleip:port', | |
'https://localhost:8080' | |
] | |
check_proxy_list(proxyList) | |
print('check finish') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment