tchar / ulauncher-albert-calculate-anything

A ULauncher/Albert extension that supports currency, units and date time conversion, as well as a calculator that supports complex numbers and functions.
MIT License
103 stars 13 forks source link

Proxy support [feature] #29

Open zefr0x opened 3 years ago

zefr0x commented 3 years ago

I don't like frequent requests from my computer to a web services, so I like to transfer the requests through Tor for this kind of tools, I usually use SOCKS5 tor proxy witch gives you socks5://127.0.0.1:9050 by default when you start tor serves.

Describe the solution you'd like

I would like to see a proxy section in the extention config page in ulauncher, or if it's hard to make it more customized you can just put an on/off button to use tor.

How to implement it?

I found thet you are using urllib to get data so you can use this solution for tor's SOCKS5 before importing urlopen:

import socket
import socks

def create_connection(addr, timeout=None, src=None):
    sock = socks.socksocket()
    sock.connect(addr)
    return sock

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050, True)

socket.socket = socks.socksocket
socket.create_connection = create_connection

# then importing urlopen
from urllib.request import urlopen

Source: https://hackeradam.com/post/how-to-route-urllib2-through-tor/

🔴🔴 Be aware about the True in:

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050, True)

If you don't use it the DNS will be leaked.

Source: https://security.stackexchange.com/questions/40414/tor-via-python-can-the-real-ip-address-leak

tchar commented 3 years ago

@ZER0-X Hello, thanks for the suggestion.

I have implemented something similar in another project of mine using requests (I even think it is possible to use the 9051 port which is the control port or whatever that's called and refresh the ip). Practically, it should not be difficult, however, these days I don't have enough time to implement and test this, due to other responsibilities.

Until I have free time (which may take months) I would be happy to accept a pull request with proper tests, or even suggest alternatives:

Maybe that doesn't sound too good, but since I am the only maintainer of the project and don't have much time to implement this at the moment, it could take some time to implement something like that. I obviously will accept a proper PR for this.

Thanks very much for taking the time to provide sample code on how to do this. It will be helpful if I start implementing this in the future.

Cheers, tchar

github-actions[bot] commented 2 years ago

Issue has been marked as stale due to no activity