|
|
//go:build !(windows && arm64)
|
|
|
|
|
|
package tcpkill
|
|
|
|
|
|
import (
|
|
|
"github.com/spf13/cobra"
|
|
|
"os"
|
|
|
"runtime"
|
|
|
)
|
|
|
|
|
|
var tck = &TCPKill{}
|
|
|
|
|
|
func init() {
|
|
|
Cmd.Flags().StringVarP(&tck.SrcIP, "src-ip", "s", "", "本地源IP")
|
|
|
Cmd.Flags().IntVarP(&tck.SrcPort, "src-port", "p", 0, "本地源端口")
|
|
|
Cmd.Flags().StringVarP(&tck.DstIP, "dst-ip", "d", "", "目标IP")
|
|
|
Cmd.Flags().IntVarP(&tck.DstPort, "dst-port", "P", 0, "目标端口")
|
|
|
Cmd.Flags().StringVarP(&tck.Status, "status", "S", "", "匹配的连接状态,如ESTABLISHED,CLOSE_WAIT等,为空则匹配所有")
|
|
|
Cmd.Flags().IntVarP(&tck.RstNumbers, "rst-numbers", "n", 3, "RST包数量")
|
|
|
Cmd.Flags().BoolVarP(&tck.WaitMode, "wait", "w", false, "等待模式")
|
|
|
Cmd.Flags().StringVarP(&tck.KillType, "kill-type", "t", "both", "RST通知类型,both=都通知 target=目标地址通知 reverse=来源地址通知")
|
|
|
if runtime.GOOS != "windows" {
|
|
|
Cmd.Flags().BoolVarP(&tck.AutoIptables, "auto-iptables", "a", true, "自动设置iptables")
|
|
|
Cmd.Flags().IntVarP(&tck.NFQNums, "nfq-nums", "q", 0, "NFQ队列号")
|
|
|
} else {
|
|
|
Cmd.Flags().StringVarP(&tck.Eth, "eth", "e", "", "网卡")
|
|
|
Cmd.Flags().StringVarP(&tck.BPF, "bpf", "b", "", "BPF过滤")
|
|
|
Cmd.Flags().StringVarP(&tck.Host, "host", "i", "", "主机")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var Cmd = &cobra.Command{
|
|
|
Use: "tcpkill",
|
|
|
Short: "杀掉那个TCP连接",
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
err := tck.Run()
|
|
|
if err != nil {
|
|
|
os.Exit(1)
|
|
|
}
|
|
|
},
|
|
|
}
|