├── .gitignore ├── LICENSE ├── README.md ├── python-requests-anonymizer ├── __init__.py ├── anonymizer.py ├── setup.py └── tests.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | .idea/ 3 | 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | .hypothesis/ 50 | .pytest_cache/ 51 | 52 | # Translations 53 | *.mo 54 | *.pot 55 | 56 | # Django stuff: 57 | *.log 58 | local_settings.py 59 | db.sqlite3 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # pyenv 78 | .python-version 79 | 80 | # celery beat schedule file 81 | celerybeat-schedule 82 | 83 | # SageMath parsed files 84 | *.sage.py 85 | 86 | # Environments 87 | .env 88 | .venv 89 | env/ 90 | venv/ 91 | ENV/ 92 | env.bak/ 93 | venv.bak/ 94 | 95 | # Spyder project settings 96 | .spyderproject 97 | .spyproject 98 | 99 | # Rope project settings 100 | .ropeproject 101 | 102 | # mkdocs documentation 103 | /site 104 | 105 | # mypy 106 | .mypy_cache/ 107 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Assem Chelli 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python-requests-anonymizer 2 | An anonymizing tool to be used for api calls. 3 | 4 | ## Requirements 5 | - tor 6 | - pip install -r requirements.txt 7 | 8 | ## Install 9 | - pip install requests_anonymizer 10 | 11 | ## Usage 12 | The torsocks proxy must be running on port 9050, start it with the command: 13 | 14 | - `service tor start` 15 | or 16 | - `systemctl start tor` 17 | 18 | 19 | You can use it as: 20 | ```python 21 | # Doing a simple GET request: 22 | anonymizer.get(url='https://httpbin.org/get?arg1=123&arg2=456').text 23 | 24 | # Doing a simple POST request: 25 | anonymizer.post(url='https://httpbin.org/post', data={'arg1':'123','arg2':'456'}).text 26 | ``` 27 | 28 | 29 | 30 | ## Disclaimer! 31 | This tool is made for test purposes. -------------------------------------------------------------------------------- /python-requests-anonymizer/__init__.py: -------------------------------------------------------------------------------- 1 | from .anonymizer import * -------------------------------------------------------------------------------- /python-requests-anonymizer/anonymizer.py: -------------------------------------------------------------------------------- 1 | import grequests 2 | TIMEOUT = 5 3 | 4 | def get(**args): 5 | args['proxies'] = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'} 6 | args['timeout'] = TIMEOUT 7 | return grequests.map([grequests.get(**args)])[0] 8 | 9 | def post(**args): 10 | args['proxies'] = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'} 11 | args['timeout'] = TIMEOUT 12 | return grequests.map([grequests.post(**args)])[0] 13 | 14 | def simultaneous_requests(lst): 15 | # lst is an array of dicts, each dict has the key 'method' that is 'get', 'post', or any other HTTP method, url, and other parameters we might want to pass to grequests.request 16 | reqs = [ ] 17 | for req in lst: 18 | req['proxies'] = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'} 19 | req['timeout'] = TIMEOUT 20 | reqs.append( grequests.request(**req) ) 21 | return grequests.map(reqs) 22 | 23 | def get_ip(): 24 | return post(url="https://icanhazip.com/").text.strip() 25 | -------------------------------------------------------------------------------- /python-requests-anonymizer/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup( 4 | name='requests_anonymizer', 5 | version='0.3', 6 | packages=['.'], 7 | url='https://github.com/assem-ch/python-requests-anonymizer', 8 | install_requires=['grequests', 'pysocks'], 9 | license='MIT', 10 | author='Assem Chelli; Niboucha Redouane', 11 | author_email='', 12 | description='An anonymizing tool to be used for requests api calls' 13 | ) 14 | -------------------------------------------------------------------------------- /python-requests-anonymizer/tests.py: -------------------------------------------------------------------------------- 1 | import anonymizer 2 | from time import time 3 | 4 | # test GET 5 | print("Doing a simple GET request:") 6 | print( anonymizer.get(url='https://httpbin.org/get?arg1=123&arg2=456').text ) 7 | 8 | # test POST 9 | print("Doing a simple POST request:") 10 | print( anonymizer.post(url='https://httpbin.org/post', data={'arg1':'123','arg2':'456'}).text ) 11 | 12 | # try checking IP between 6 successive requests 13 | print("Doing 6 requests, and measuring time taken") 14 | t = time() 15 | for i in range(6): 16 | print(anonymizer.get_ip()) 17 | print("Time taken : " + str(time() - t)) 18 | # try simultaneous requests 19 | print("Doing 6 simultaneous requests, and measuring time taken") 20 | obj = { 'method': 'GET', 'url': "https://icanhazip.com/" } 21 | t = time() 22 | print([x.text for x in anonymizer.simultaneous_requests( [ obj, obj, obj, obj, obj, obj ] )]) 23 | print("time taken in simultaneous_requests : " + str(time() - t)) 24 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/assem-ch/python-requests-anonymizer/f6bf3ad8c54d8db113f374ba7afabfc7e70bedcd/requirements.txt --------------------------------------------------------------------------------