File size: 1,057 Bytes
3f64f4a
 
 
06cf26e
3f64f4a
06cf26e
 
3f64f4a
 
 
06cf26e
 
 
 
 
 
 
 
 
 
3f64f4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
06cf26e
3f64f4a
 
 
06cf26e
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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>")