Issue
I am using python3 asyncio_socks_server library to run a socks proxy, my program is supposed to run a socks proxy in a thread and an HTTP server on another thread then continue execution. Here is my socks_proxy.py:
import socket
from asyncio_socks_server.__version__ import __version__
from asyncio_socks_server.app import SocksServer
class SocksProxy:
def __init__(self, local_ip, port):
args = []
config_args = {
"LISTEN_HOST": local_ip,
"LISTEN_PORT": port,
"AUTH_METHOD": 0,
"ACCESS_LOG": 0,
"DEBUG": 1,
"STRICT": 0,
}
app = SocksServer(
config=None,
env_prefix="AIOSS_",
**{k: v for k, v in config_args.items() if v is not None},
)
app.run()
def startSocksProxy(local_ip, port):
s = SocksProxy(local_ip, port)
main.py:
import threading
from modules.util.socks_proxy import startSocksProxy
from modules.logger.logger import Logger
if "__main__" == __name__:
logger = Logger()
remoteLog = threading.Thread(target=startLoggerServer)
remoteLog.start()
socksProxy = threading.Thread(target=startSocksProxy, args=(LOCAL_IP, 7000))
socksProxy.start()
The HTTP server starts fine, however, I am getting the following error:
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "j:\WormScanner\modules\util\socks_proxy.py", line 35, in startSocksProxy
s = SocksProxy(local_ip, port)
File "j:\WormScanner\modules\util\socks_proxy.py", line 26, in __init__
app = SocksServer(
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\asyncio_socks_server\app.py", line 23, in __init__
self.loop = asyncio.get_event_loop()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\asyncio\events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-2'.
and the socks proxy doesn't start.
Solution
To anyone who ever faces this problem, it worked fine when I used multiprocessing:
if "__main__" == __name__:
multiprocessing.freeze_support()
remoteLog = multiprocessing.Process(target=startLoggerServer)
remoteLog.start()
socksProxy = multiprocessing.Process(target=startSocksProxy, args=(LOCAL_IP, 7000))
socksProxy.start()
Answered By - user7864052
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.