OteCortes/Anopymizer
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
#### Anonymizer ####
Anonymize http petitions thru a proxy or a Tor connection.
Copyright (C) 2012 Angel Cortés
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of copyright holders nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
#Resume
This class is to simplify the work with HTTP GET petitions trying to anonymize them as example to get access to
APIs with throttle control.
If you configure access to a TOR Control port, autoconfigure fast recicle circuits(60 secs) and request a new one
when you prepare a petition after this 60 seconds. With this, the Anonymizer, controls the number of petitions with
the same IP and launch an AnonymizerException if you try to do more petitions in this time.
#Author
Angel -Ote- Cortés @OteCortes
#Python
-Tested on 2.7.1(Linux)
-Tested on 3.2(Windows)
#Version
-0.1: First release
-Accepts the use of TOR Control protocol port to request new circuits
-Limit the rate of TOR petitions per minute and change the circuit when a petition is done after a minute.
-Randomize Accept-Languaje(6) and User-Agent(15) headers.
#TODO
-Document ExceptionCodes
-HTTP POST
-Option to autoremove not available proxies
-IPv6 support for TOR control protocol
#Example Code
-Using HTTP proxies
from anonymizer import Anonymizer
test_proxy = {'http':["1.1.1.1:3128","2.2.2.2:3128","3.3.3.3:3128","4.4.4.4:3128","5.5.5.5:3128"]}
if __name__ == "__main__":
anon = Anonymizer(test_proxy)
#Normal petition to Google with random HTTP proxy from list
res = anon.get("http://www.google.com")
#Print Data obtained
print(res.text)
#Print the cookies send by google
print(res.cookies)
print("#####################")
#PureAnon petition to google with random HTTP proxy from list
res = anon.get("http://www.google.com",pureAnon = True)
#Print Data obtained
print(res.text)
#Print the cookies send by google
print(res.cookies)
-Using TOR
You can call it as a simple HTTP proxy as parameter of the previous example or use the 'tor'
from anonymizer import Anonymizer
test_tor = {'tor':"127.0.0.1:8118"}
if __name__ == "__main__":
anon = Anonymizer(test_tor)
res = anon.get("http://whatsmyip.net/")
#Print Data obtained
print(res.text)
-Using TOR with TOR Control port access
You can configure number of petitions per second(and need to handle it) and a TOR Control port and host to connect and create
new circuits after this time.
from anonymizer import Anonymizer
from time import sleep
test_tor = {'tor':"127.0.0.1:8118",'torctl':"127.0.0.1:9051"}
if __name__ == "__main__":
anon = Anonymizer(test_tor,passwd="1234",petitions=6)
#I will do 10 petitions
for i in range(10):
try:
res = anon.get("http://whatsmyip.net/")
except AnonymizerException as e:
if e.errorCode == 111:
print(e)
print("Too much petitions with this IP...sleeping 30 secs")
sleep(30)
continue
print("---->Petition Tor %s"%i)
print("---->IP:")
print(res.text.split("<title>")[1].split("</title>")[0])
print("----------------------------")
#(sleep 10 seconds + the petition time) > 60sec/6petitions
sleep(10)