Compare commits

...

2 Commits

View File

@ -26,11 +26,19 @@ import (
"github.com/fatedier/frp/pkg/nathole" "github.com/fatedier/frp/pkg/nathole"
) )
var (
natHoleSTUNServer string
serverUDPPort int
)
func init() { func init() {
RegisterCommonFlags(natholeCmd) RegisterCommonFlags(natholeCmd)
rootCmd.AddCommand(natholeCmd) rootCmd.AddCommand(natholeCmd)
natholeCmd.AddCommand(natholeDiscoveryCmd) natholeCmd.AddCommand(natholeDiscoveryCmd)
natholeCmd.PersistentFlags().StringVarP(&natHoleSTUNServer, "nat_hole_stun_server", "", "stun.easyvoip.com:3478", "STUN server address for nathole")
natholeCmd.PersistentFlags().IntVarP(&serverUDPPort, "server_udp_port", "", 0, "UDP port of frps for nathole")
} }
var natholeCmd = &cobra.Command{ var natholeCmd = &cobra.Command{
@ -42,10 +50,13 @@ var natholeDiscoveryCmd = &cobra.Command{
Use: "discover", Use: "discover",
Short: "Discover nathole information by frps and stun server", Short: "Discover nathole information by frps and stun server",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
cfg, _, _, err := config.ParseClientConfig(cfgFile) // ignore error here, because we can use command line pameters
if err != nil { cfg, _, _, _ := config.ParseClientConfig(cfgFile)
fmt.Println(err) if natHoleSTUNServer != "" {
os.Exit(1) cfg.NatHoleSTUNServer = natHoleSTUNServer
}
if serverUDPPort != 0 {
cfg.ServerUDPPort = serverUDPPort
} }
if err := validateForNatHoleDiscovery(cfg); err != nil { if err := validateForNatHoleDiscovery(cfg); err != nil {