Skip to content

Instantly share code, notes, and snippets.

@CNSumi
Created February 21, 2019 13:39
Show Gist options
  • Save CNSumi/f78d569943b570ff3cd6d5680ebe8b77 to your computer and use it in GitHub Desktop.
Save CNSumi/f78d569943b570ff3cd6d5680ebe8b77 to your computer and use it in GitHub Desktop.
xshell
@CNSumi
Copy link
Author

CNSumi commented Feb 21, 2019

####登录脚本

'  path指向的文件内容需要是{user} {password} {ip}的行
Sub Main

    PATH = "C:\apps\tools\login\a.eml"

    ip = xsh.Dialog.Prompt ("Pleaer input last 2 or 3 numbers of server ip", "Prompt Dialog", "", 0)

    if Len(ip)=0 then
        xsh.Dialog.MsgBox("No Input !")
    else
        data = ReadSomeLine(path)
        results = Split(data, vbCrLf)
        login = True
        for each result in results
            a = Split(result, " ")
            tmp = Split(a(2), ".")(3)
            if ip=tmp Then
                login = False
                xsh.Screen.Send("ssh " & a(0) & "@" & a(2))
                xsh.Screen.Send(VbCr)
                xsh.Screen.WaitForString("password:")
                xsh.Screen.Send(a(1))
                xsh.Screen.Send(VbCr)
                xsh.Screen.Send("sudo su")
                xsh.Screen.Send(VbCr)
                xsh.Screen.Send("gocnews")
                xsh.Screen.Send(VbCr)
            end if
        Next
        if login then
            xsh.Dialog.MsgBox("No Match !")
        end if

    end if
End Sub

Function RegExpTest(patrn, strng)
    Dim regEx, Match, Matches
    Set regEx = New RegExp
    regEx.Pattern = patrn
    regEx.IgnoreCase = True
    regEx.Global = True
    Set Matches = regEx.Execute(strng)
    for each Match in Matches
        RetStr = RetStr & Match.SubMatches(0) & ":" & Match.SubMatches(1) & ":" & Match.SubMatches(2) & "|"
    Next
    RegExpTest = Left(RetStr, Len(RetStr)-1)
End Function


Function ReadSomeLine(path)
    Set fso = CreateObject("scripting.filesystemobject")
    Set A=fso.OpenTextFile(path,1)
    ReadSomeLine=A.ReadAll
End Function

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