Skip to content

Instantly share code, notes, and snippets.

@happyman
Last active October 21, 2021 04:25
Show Gist options
  • Select an option

  • Save happyman/36e2e9105949f91e6ad9ac25794e3612 to your computer and use it in GitHub Desktop.

Select an option

Save happyman/36e2e9105949f91e6ad9ac25794e3612 to your computer and use it in GitHub Desktop.
login OPTIMA by KiTTY
##
## KiTTY can do auto-login, and initial command.
##
## start first Kitty to get OTP
$app = Start-Process -FilePath C:\Users\happyman\Desktop\kitty_portable-0.74.4.13.exe -ArgumentList '-load soptima' -passthru
Write-Output "get OTP and sleep 15 secs"
Start-Sleep -s 15
taskkill /PID $app.Id /f
Write-Output "re-spawn kitty soptima"
$otp = (python .\otp.py)
Write-Output "get otp $otp ..."
$app = Start-Process -FilePath C:\Users\happyman\Desktop\kitty_portable-0.74.4.13.exe -ArgumentList "-load soptima -cmd $otp" -passthru
## check if otp changed?
$otp = (python .\otp.py)
Write-Output "re-get otp $otp for manual input, in case 15 secs not enough"
@happyman
Copy link
Author

use http://www.9bis.net/kitty/#!pages/LogonScript.md to send username, password
use http://www.9bis.net/kitty/#!pages/AutomaticCommand.md to send OTP

of course, you need a way to retrieve your OTP by script. (mine otp.py here)

@happyman
Copy link
Author

python version

##
## KiTTY can do auto-login, and initial command.
## 
## python version of 
## https://gist.github.com/happyman/36e2e9105949f91e6ad9ac25794e3612
from subprocess import Popen
import os, re, sys
import otp
import getopt

profile = "soptima"
opts, argv = getopt.getopt(sys.argv[1:], "l:h")
for o, v in opts:
    if o == "-h":
        print(sys.argv[0],"[-h help, -l spams|spotima]")
        sys.exit()
    elif o == "-l":
        if v != "":
            profile = v

## 8 分鐘內 ok
myotp = otp.getotp_ifok()
if myotp is None:
    cmd=r"C:\Users\happyman\Desktop\kitty_portable-0.74.4.13.exe -load "+profile
    p = Popen(cmd.split())
    print("Process ID:", p.pid)
    myotp = otp.ws_getotp()
    os.kill(p.pid,9)

print("OTP is "+myotp)
cmd = r"C:\Users\happyman\Desktop\kitty_portable-0.74.4.13.exe -load "+profile+ " -cmd "+myotp
p = Popen(cmd.split())
print("Process ID:", p.pid)

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