proxytools

- collection of scripts for harvesting & testing proxies
git clone git://git.acid.vegas/proxytools.git
Log | Files | Refs | Archive | README | LICENSE

dronebl.py (3051B)

      1 #!/usr/bin/env python
      2 # Copyright (c) 2008 DroneBL contributors
      3 #
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without modification,
      7 # are permitted provided that the following conditions are met:
      8 #
      9 #      Redistributions of source code must retain the above copyright notice,
     10 #      this list of conditions and the following disclaimer.
     11 #
     12 #      Redistributions in binary form must reproduce the above copyright notice,
     13 #      this list of conditions and the following disclaimer in the documentation
     14 #      and/or other materials provided with the distribution.
     15 #
     16 #      Neither the name of the author nor the names of its contributors may be
     17 #      used to endorse or promote products derived from this software without
     18 #      specific prior written permission.
     19 #
     20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     23 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
     24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     27 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     29 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30 
     31 class DroneBLClient:
     32 	"""Class for accessing DroneBL."""
     33 	def __init__(self, rpckey=None, server="https://dronebl.org/RPC2"):
     34 		self.server = server
     35 		self.rpckey = rpckey
     36 		self.submitList = ""
     37 
     38 	def addIP(self, ip, type):
     39 		"""Adds IP to DroneBL."""
     40 		self.submitList += "\t<add ip='" + ip + "' type='" + str(type) + "' />\n";
     41 
     42 	def lookupIP(self, ip):
     43 		"""Adds a lookup request to the message."""
     44 		self.submitList += "\t<lookup ip='" + ip + "' />\n"
     45 
     46 	def makeRequest(self):
     47 		"""Generates the request."""
     48 		self.request = "<?xml version=\"1.0\"?>\n<request key='" + self.rpckey + "'>\n" + self.submitList + "</request>"
     49 
     50 	def showRequest(self):
     51 		"""Shows the request."""
     52 		self.makeRequest()
     53 		print self.request
     54 
     55 	def makeConnection(self):
     56 		"""Connects to the RPC server."""
     57 		import urllib
     58 		type, uri = urllib.splittype(self.server)
     59 		self.__host, self.__handler = urllib.splithost(uri)
     60 
     61 		import httplib
     62 		self.connection = httplib.HTTPConnection(self.__host)
     63 
     64 	def postRequest(self):
     65 		"""Executes the request."""
     66 		self.makeRequest()
     67 		self.makeConnection()
     68 		self.connection.putrequest("POST", self.__handler)
     69 		self.connection.putheader("Content-Type", "text/xml")
     70 		self.connection.putheader("Content-Length", str(int(len(self.request))))
     71 		self.connection.endheaders()
     72 		self.connection.send(self.request)
     73 		self.__response = self.connection.getresponse()
     74 
     75 	def printResponse(self):
     76 		"""Display the XML response."""
     77 		print self.__response.read()
     78