ends article branch
This commit is contained in:
@@ -58,7 +58,7 @@ func setupKnockRoutes(api *gin.RouterGroup) {
|
||||
c.JSON(400, gin.H{"error": "targets is required in inline mode"})
|
||||
return
|
||||
}
|
||||
config, err := parseInlineTargetsWithWait(req.Targets, req.Delay, req.WaitConnection)
|
||||
config, err := parseInlineTargetsWithWait(req.Targets, req.Delay, req.WaitConnection, req.Gateway)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": fmt.Sprintf("invalid targets: %v", err)})
|
||||
return
|
||||
@@ -81,7 +81,7 @@ func setupKnockRoutes(api *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
// parseInlineTargetsWithWait парсит inline строку целей в Config с поддержкой waitConnection
|
||||
func parseInlineTargetsWithWait(targets, delay string, waitConnection bool) (internal.Config, error) {
|
||||
func parseInlineTargetsWithWait(targets, delay string, waitConnection bool, gateway string) (internal.Config, error) {
|
||||
var config internal.Config
|
||||
|
||||
// Парсим targets
|
||||
@@ -93,13 +93,18 @@ func parseInlineTargetsWithWait(targets, delay string, waitConnection bool) (int
|
||||
}
|
||||
|
||||
parts := strings.Split(targetStr, ":")
|
||||
if len(parts) != 3 {
|
||||
return config, fmt.Errorf("invalid target format: %s (expected protocol:host:port)", targetStr)
|
||||
if !(len(parts) == 3 || len(parts) == 4) {
|
||||
return config, fmt.Errorf("invalid target format: %s (expected protocol:host:port or protocol:host:port:gateway)", targetStr)
|
||||
}
|
||||
|
||||
protocol := strings.TrimSpace(parts[0])
|
||||
host := strings.TrimSpace(parts[1])
|
||||
portStr := strings.TrimSpace(parts[2])
|
||||
|
||||
|
||||
if len(parts) == 4 {
|
||||
gateway = strings.TrimSpace(parts[3])
|
||||
}
|
||||
|
||||
if protocol != "tcp" && protocol != "udp" {
|
||||
return config, fmt.Errorf("unsupported protocol: %s (only tcp/udp supported)", protocol)
|
||||
@@ -128,6 +133,7 @@ func parseInlineTargetsWithWait(targets, delay string, waitConnection bool) (int
|
||||
Ports: []int{port},
|
||||
Delay: targetDelay,
|
||||
WaitConnection: waitConnection,
|
||||
Gateway: gateway,
|
||||
}
|
||||
|
||||
config.Targets = append(config.Targets, target)
|
||||
|
@@ -6,6 +6,7 @@ require (
|
||||
github.com/gin-contrib/cors v1.7.2
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/spf13/cobra v1.8.0
|
||||
golang.org/x/sys v0.20.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
@@ -35,7 +36,6 @@ require (
|
||||
golang.org/x/arch v0.8.0 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
golang.org/x/text v0.15.0 // indirect
|
||||
google.golang.org/protobuf v1.34.1 // indirect
|
||||
)
|
||||
|
@@ -287,7 +287,12 @@ func (pk *PortKnocker) knockTarget(target Target, verbose bool) error {
|
||||
|
||||
for i, port := range target.Ports {
|
||||
if verbose {
|
||||
fmt.Printf(" Отправка пакета на %s:%d (%s)\n", target.Host, port, protocol)
|
||||
if target.Gateway != "" {
|
||||
fmt.Printf(" Отправка пакета на %s:%d (%s) через шлюз %s\n", target.Host, port, protocol, target.Gateway)
|
||||
} else {
|
||||
fmt.Printf(" Отправка пакета на %s:%d (%s)\n", target.Host, port, protocol)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if err := pk.sendPacket(target.Host, port, protocol, target.WaitConnection, timeout, target.Gateway); err != nil {
|
||||
|
Reference in New Issue
Block a user