Spaces:
Paused
Paused
| import subprocess | |
| import os | |
| import sys | |
| import json | |
| CONFIG_FILE = "pc_config.json" | |
| DEFAULT_IP = "192.168.100.35" | |
| PORT = 8022 | |
| USER = "u0_a410" | |
| config = {} | |
| if os.path.exists(CONFIG_FILE): | |
| with open(CONFIG_FILE) as f: | |
| config = json.load(f) | |
| IP = config.get("ip", DEFAULT_IP) | |
| if len(sys.argv) > 1: | |
| IP = sys.argv[1] | |
| ssh_paths = [ | |
| r"C:\Windows\System32\OpenSSH\ssh.exe", | |
| r"C:\Program Files\Git\usr\bin\ssh.exe", | |
| "ssh", | |
| ] | |
| ssh = None | |
| for p in ssh_paths: | |
| try: | |
| subprocess.run([p, "-V"], capture_output=True) | |
| ssh = p | |
| break | |
| except: | |
| continue | |
| if not ssh: | |
| print("Nie znaleziono SSH. Zainstaluj OpenSSH lub Git.") | |
| print("Jako Admin: Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0") | |
| sys.exit(1) | |
| print(f"Lacze z {USER}@{IP}:{PORT}...") | |
| code = os.system(f'""{ssh}" {USER}@{IP} -p {PORT}"') | |
| if code != 0: | |
| print(f"\nBlad polaczenia. Sprawdz IP telefonu.") | |
| print(f"Na telefonie uruchom: bash termux_host.sh") | |
| print(f"Lub podaj IP: python PCconnector.py <nowe_ip>") | |