- Is the proxy server available - this check refers to the proxy server connectivity.
- Is the proxy server correct - this check is performed to see whether a proxy server is providing the requested webpage or replies with a random webpage.
The following Python code for testing IP:Port proxy servers can be used as a guidance:
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
import urllib | |
def is_proxy_working(ip, port): | |
proxy_ip_port = 'http://%s:%s' % (ip, port) | |
response = urllib.urlopen( "http://www.testpage.com", | |
proxies={}) | |
test_page_len = len(response.read()) | |
#Start check for criteria 1. | |
try: | |
response = urllib.urlopen( "http://www.testpage.com", | |
proxies={'http':proxy_ip_port}) | |
except: | |
return False | |
#End check for criteria 1. | |
#Start check for criteria 2. | |
test_page_len_with_proxy = len(response.read()) | |
if test_page_len == test_page_len_with_proxy: | |
return True | |
else: | |
return False | |
#End check for criteria 2. |
It is important to ensure that the webpage used for testing (http://www.testpage.com) is reachable and static. If the webpage is neither reachable nor static then the above test will indicate a proxy failure, which in fact is a false alarm!
- A list of IP:Port proxy servers can be obtained from Hide My Ass .