elleryq
12/27/2014 - 9:42 AM

在 putty 裡輸入 tunnel,預設熱鍵是 Windows + P。cnproxy.py 在這裡 https://gist.github.com/elleryq/aff74c950863cad69faa#

在 putty 裡輸入 tunnel,預設熱鍵是 Windows + P。cnproxy.py 在這裡 https://gist.github.com/elleryq/aff74c950863cad69faa#

; Execute command and read stdout.
CuteRun(c) {
    full_command := comspec . " /c """ . c . """"
    shell := comobjcreate("wscript.shell")
    exec := (shell.exec(full_command))
    stdout := exec.stdout.readall()
    Return stdout
}

#P::
  proxy_string := CuteRun("python your_path\cnproxy.py")
  ;DllCall("shlwapi\PathRemoveBlanksA", proxy_string, proxy)
  StringTrimRight, proxy, proxy_string, 2

  ; Check empty or not.
  StringReplace, proxy_string, proxy, :, , All
  proxy_length := StrLen(proxy_string)
  if proxy_length <= 0
  {
    MsgBox No Proxy returned.
    return
  }

  IfWinExist, ellery :: cyrix200 ::
  {
    WinActivate  ; Automatically uses the window found above.
  }
  else
  {
    v_program=%A_ProgramFiles%\PuTTY\putty.exe -load home
    run, %v_program% , , , newpid
    winwait, ahk_pid %newpid%
    sleep, 1000
    ControlSend, , ellery{enter}, ahk_pid %newpid%
    sleep, 5000
    ControlSend, , tmux attach -t 0{enter}, ahk_pid %newpid%
  }

  CoordMode Mouse, Window
  ; Click the icon on title bar.
  Click 5, 5
  ; Change settings
  Click 60, 285

  ; Wait 
  sleep, 500
  WinWait, PuTTY Reconfiguration

  ; Expand SSH
  Click 40, 270

  ; Select tunnels
  Click 90, 300

  ; Focus 'Source' and type text.
  Sleep 1000
  ;ControlFocus, Edit, ahk_id 0x0000041B
  Send !s
  sleep 100
  Send 13128
  sleep 100

  ; Focus "Destination' and type text.
  ;ControlFocus, Edit, ahk_id 0x0000041D
  Send !i
  sleep 100
  Send %proxy%
  sleep 100

  ; Select IPv4
  ;ControlClick, IPv4
  Send !4
  sleep 100
  ; Click Add
  ;ControlClick, Add
  Send !d

  sleep, 2000
  ; Click Apply
  ;ControlClick, Apply
  Send !A
return