Files
windows-rdp-keylogger/cmd/client/connect.go
T

45 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"bufio"
"fmt"
"net"
"os"
"strconv"
"strings"
)
const defaultPort = "47812"
// promptForHostAddress interactively asks for the host's IP (its LAN
// address, or its WireGuard/VPN address when connecting from outside the
// physical LAN) and port, for when -host wasn't passed on the command
// line.
func promptForHostAddress() (string, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Host IP (LAN address, or its WireGuard/VPN address if connecting remotely): ")
ipLine, err := reader.ReadString('\n')
if err != nil {
return "", err
}
ip := strings.TrimSpace(ipLine)
if ip == "" {
return "", fmt.Errorf("no IP entered")
}
fmt.Printf("Port [%s]: ", defaultPort)
portLine, err := reader.ReadString('\n')
if err != nil {
return "", err
}
portStr := strings.TrimSpace(portLine)
if portStr == "" {
portStr = defaultPort
}
if _, err := strconv.ParseUint(portStr, 10, 16); err != nil {
return "", fmt.Errorf("invalid port %q", portStr)
}
return net.JoinHostPort(ip, portStr), nil
}