SSHTunnel/Main.go

47 lines
967 B
Go
Raw Normal View History

2015-01-02 15:51:37 +00:00
package main
import (
2015-09-23 18:30:44 +00:00
"fmt"
2015-01-02 15:51:37 +00:00
"golang.org/x/crypto/ssh"
"runtime"
2015-01-02 15:51:37 +00:00
)
func main() {
2015-09-23 18:30:44 +00:00
// Show the current version:
fmt.Println(`SSHTunnel v1.1.0`)
// Allow Go to use all CPUs:
runtime.GOMAXPROCS(runtime.NumCPU())
// Read the configuration from the command-line args:
2015-01-02 15:51:37 +00:00
readFlags()
2015-09-23 18:30:44 +00:00
// Check if the password was provided:
for true {
if password == `` {
// Promt for the password:
fmt.Println(`Please provide the password for the connection:`)
fmt.Scanln(&password)
} else {
break
}
}
// Create the SSH configuration:
2015-01-02 15:51:37 +00:00
config := &ssh.ClientConfig{
User: username,
Auth: []ssh.AuthMethod{
ssh.Password(password),
ssh.PasswordCallback(passwordCallback),
ssh.KeyboardInteractive(keyboardInteractiveChallenge),
},
}
// Create the local end-point:
localListener := createLocalEndPoint()
2015-01-02 15:51:37 +00:00
// Accept client connections (will block forever):
acceptClients(localListener, config)
2015-01-02 15:51:37 +00:00
}