Skip to content

Instantly share code, notes, and snippets.

@kerenskybr
Last active April 5, 2021 13:26
Show Gist options
  • Save kerenskybr/d31524817449031acde93fb78aab408a to your computer and use it in GitHub Desktop.
Save kerenskybr/d31524817449031acde93fb78aab408a to your computer and use it in GitHub Desktop.
Script to test websockets with/out luminati proxy
import websocket
try:
import thread
except ImportError:
import _thread as thread
import time
import argparse
import socks
parser = argparse.ArgumentParser()
parser.add_argument('--port', action='store', type=str)
parser.add_argument('--proxy', action='store', type=bool, default=False)
parser.add_argument('--socks5', action='store', type=bool, default=False)
args = vars(parser.parse_args())
print(args['port'])
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
def run(*args):
for i in range(3):
time.sleep(1)
ws.send("Hello %d" % i)
time.sleep(1)
ws.close()
print("thread terminating...")
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
if args['port'] == 443:
prefix = 'wss'
else:
prefix = 'ws'
ws = websocket.WebSocketApp(
url= prefix + '://104.131.103.83:' + args['port'],
on_open = on_open,
on_message = on_message,
on_error = on_error,
on_close = on_close,
)
if args['socks5']:
ws.run_forever(
http_proxy_host='localhost',
http_proxy_port= 1337,
proxy_type='socks5',
)
if args['proxy']:
ws.run_forever(
http_proxy_host='zproxy.lum-superproxy.io',
http_proxy_port= 22225,
http_proxy_auth=('lum-customer-c_bd47b35e-zone-static_res','raph5hlg63iu'),
)
else:
ws.run_forever()
ws.close()
# curl -x http://zproxy.lum-superproxy.io:22225 --proxy-user lum-customer-c_bd47b35e-zone-static_res:raph5hlg63iu -L http://httpbin.org/ip
@kerenskybr
Copy link
Author

kerenskybr commented Apr 2, 2021

Usage:
python websocket_client.py --port *port* --proxy *True*
Available ports are 80, 443 and 5080
(only working without the --proxy option)


For test with socks5, need to activate the server proxy on same client machine (running this script):
ssh -D 1337 -C -N testuser@162.243.26.49
Password: Passw0rd!

And run the script with --scoks5 option instead of --proxy:
python websocket_client.py --port *port* --socks5 *True*
Available ports are 80, 443 and 5080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment