package bridge
import (
"context"
"strconv"
"strings"
"github.com/masterzen/winrm"
)
func InitWinRm (username , password , host , port string , secure bool ) (*winrm .Client , error ) {
winrmPort , _ := strconv .Atoi (port )
endpoint := winrm .NewEndpoint (host , winrmPort , secure , true , nil , nil , nil , 0 )
params := winrm .DefaultParameters
params .TransportDecorator = func () winrm .Transporter {
return &winrm .ClientNTLM {}
}
client , err := winrm .NewClientWithParameters (endpoint , username , password , params )
if err != nil {
return nil , err
}
return client , nil
}
func VerifyWinRm (username , password , host , port string , secure bool ) bool {
winrmPort , _ := strconv .Atoi (port )
endpoint := winrm .NewEndpoint (host , winrmPort , secure , true , nil , nil , nil , 0 )
params := winrm .DefaultParameters
params .TransportDecorator = func () winrm .Transporter {
return &winrm .ClientNTLM {}
}
client , err := winrm .NewClientWithParameters (endpoint , username , password , params )
if err != nil {
return false
}
stdout , _ , _ , _ := client .RunWithContextWithString (context .TODO (), "hostname" , "" )
return strings .TrimSpace (stdout ) != ""
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .