Wednesday, 27 November 2013

Testing an IP:Port Proxy Server

It is common to use proxy servers to query webpages using programs written in Python, Java, etc. In doing so, it is necessary to maintain a list of proxies which are guaranteed to work as and when we make a webpage query. This can be done by storing a list of proxies in a database and by running a daemon to periodically check whether a particular proxy does what it is supposed to do. There are two important things that you need to consider in testing a proxy server:
  1. Is the proxy server available - this check refers to the proxy server connectivity.
  2. 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:

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.
view raw gistfile1.py hosted with ❤ by GitHub

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 .


No comments:

Post a Comment