Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions control.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from endpoints import run_server, ThreadedHTTPServer
import sys
import signal

import time
USER_JSON_FILE = "user.json"

def load_user_mapping():
Expand All @@ -32,7 +32,7 @@ def get_connected_devices():

def start_scrcpy(serial):
try:
scrcpy_path = r"C:\Users\Chaos\Documents\scrcpy-win64-v2.4\scrcpy.exe" # Replace this with the full path to scrcpy
scrcpy_path = r"C:\Program Files\scrcpy-win64-v2.4\scrcpy.exe" # Replace this with the full path to scrcpy
print("Starting scrcpy with device:", serial)
command = [scrcpy_path, '-s', serial]
print("Executing command:", command)
Expand Down Expand Up @@ -101,6 +101,54 @@ def connect_device():
return
start_scrcpy(selected_device)

def execute_adb_command(command):
subprocess.run(command, check=True, shell=True)

def create_proxy_thread(serial):
try:
print("Disabling Plane mode")
execute_adb_command(f"adb -s {serial} shell cmd connectivity airplane-mode disable")
print("Disabling Wifi")
execute_adb_command(f"adb -s {serial} shell svc wifi disable")
print("Enabling Mobile data")
execute_adb_command(f"adb -s {serial} shell svc data enable")
print("Enabling USB tethering")
try:
execute_adb_command(f"adb -s {serial} shell svc usb setFunctions rndis")
except Exception as e:
print("ignoring exepection") # adb gives exit code 255 for some reason?
time.sleep(5)
output = subprocess.run(f"adb -s {serial} shell cat /proc/net/arp", check=True, shell=True,capture_output=True).stdout.decode('utf-8')
ip = output.split("\n")[1].split(" ")[0]
print(ip)
text = f"Rotating Proxy Info:\r\n IP:{ip}:1080\r\nReset Link:http://127.0.0.1:8000/ipreset?serial={serial}"
print(text)
messagebox.showinfo("Rotating Proxy Created!",text)
except Exception as e:
print("Exception:", e)
messagebox.showerror("Error", str(e))

def create_proxy_with_serial(serial):
try:
print("Starting rotating proxy with device:", serial)
proxy_thread = threading.Thread(target=create_proxy_thread, args=(serial,))
proxy_thread.start()

except Exception as e:
print("Exception:", e)
messagebox.showerror("Error", str(e))

def create_proxy():
selected_index = device_listbox.curselection()
if selected_index:
selected_device = device_listbox.get(selected_index[0])
user_mapping = load_user_mapping()
for serial, name in user_mapping.items():
if name == selected_device:
create_proxy_with_serial(serial)
return
create_proxy_with_serial(selected_device)

def kill_server_by_serial():
serial_to_kill = serial_kill_entry.get().strip()
if serial_to_kill:
Expand Down Expand Up @@ -289,6 +337,9 @@ def refresh_running_endpoints():
connect_button = ttk.Button(buttons_frame, text="Connect", command=connect_device)
connect_button.pack(side=tk.LEFT, padx=5)

create_proxy_button = ttk.Button(buttons_frame, text="Create Rotating proxy", command=create_proxy)
create_proxy_button.pack(side=tk.LEFT, padx=5)

console_window = None
console_button = ttk.Button(buttons_frame, text="Show Console", command=show_console)
console_button.pack(side=tk.RIGHT, padx=5)
Expand All @@ -310,5 +361,5 @@ def refresh_running_endpoints():

# Start updating the list of running endpoints periodically
refresh_running_endpoints()

threading.Thread(target=run_server, args=(8000, "NULL"), daemon=True).start()
root.mainloop()
78 changes: 44 additions & 34 deletions endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import time
import os
from urllib.parse import urlparse, parse_qs

class RequestHandler(BaseHTTPRequestHandler):
request_count = 0
Expand All @@ -14,45 +15,54 @@ def execute_adb_command(self, command):
return True
except subprocess.CalledProcessError:
return False

def do_POST(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()

self.handle_request()

def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()

self.handle_request()

def handle_request(self):
with self.lock:
self.request_count += 1
count = self.request_count

if count >= 1:
if self.execute_adb_command(f"adb -s {self.server.serial} shell svc data disable"):
time.sleep(5)
if self.execute_adb_command(f"adb -s {self.server.serial} shell svc data enable"):
self.wfile.write(b'Phone data toggled successfully.')
else:
self.wfile.write(b'Failed to enable phone data.')
parsed_url = urlparse(self.path)

# Extract query parameters
query_params = parse_qs(parsed_url.query)

# Get the value of the 'serial' parameter


if parsed_url.path == "/ipreset":
serial = query_params.get('serial', [None])[0]
if serial == None:
self.send_response(400)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes(f"Missing serial parameter", "utf-8"))
else:
self.wfile.write(b'Failed to disable phone data.')
with self.lock:
self.request_count = 0
result = self.handle_request(serial)
if result:
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes(f"Phone data toggled successfully.", "utf-8"))
else:
self.send_response(500)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes(f"Failed to disable phone data.", "utf-8"))
else:
while True:
with self.lock:
if self.request_count >= 3:
break
self.send_response(404)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes(f"404 not found", "utf-8"))


def handle_request(self,serial):
if self.execute_adb_command(f"adb -s {serial} shell cmd connectivity airplane-mode enable"):
time.sleep(5)
if self.execute_adb_command(f"adb -s {serial} shell cmd connectivity airplane-mode disable"):
time.sleep(1)
return True
else:
return False
else:
return False



self.wfile.write(b'')

class ThreadedHTTPServer(HTTPServer):
running_servers = {}
Expand Down