packagemainimport("crypto/rand""flag""fmt""math/big""net""os""strconv""strings""time""golang.org/x/net/icmp""golang.org/x/net/ipv4")funcsendTCPSYN(ipstring,portuint16){address:=net.JoinHostPort(ip,strconv.Itoa(int(port)))conn,err:=net.DialTimeout("tcp",address,2*time.Second)iferr!=nil{fmt.Println("TCP SYN sent (no connection):",err)return}deferconn.Close()fmt.Println("TCP connection established (SYN sent)")}funcsendUDP(ipstring,portuint16){address:=net.JoinHostPort(ip,strconv.Itoa(int(port)))conn,err:=net.Dial("udp",address)iferr!=nil{fmt.Println("UDP error:",err)return}deferconn.Close()conn.Write([]byte("hello"))fmt.Println("UDP packet sent")}funcsendICMP(ipstring){conn,err:=icmp.ListenPacket("ip4:icmp","0.0.0.0")iferr!=nil{fmt.Println("ICMP listen error:",err)return}deferconn.Close()msg:=icmp.Message{Type:ipv4.ICMPTypeEcho,Code:0,Body:&icmp.Echo{ID:os.Getpid()&0xffff,Seq:1,Data:[]byte("ping"),},}data,_:=msg.Marshal(nil)_,err=conn.WriteTo(data,&net.IPAddr{IP:net.ParseIP(ip)})iferr!=nil{fmt.Println("ICMP send error:",err)return}fmt.Println("ICMP echo sent")}funcparsePort(portstring)[]uint16{ifport==""{return[]uint16{}}// parse port rangeifstrings.Contains(port,"-"){ports:=strings.Split(port,"-")iflen(ports)!=2{return[]uint16{}}start,_:=strconv.Atoi(ports[0])end,_:=strconv.Atoi(ports[1])ifstart<1||start>65535||end<1||end>65535||start>end{return[]uint16{}}portsInt:=make([]uint16,end-start+1)fori:=start;i<=end;i++{portsInt[i-start]=uint16(i)}returnportsInt}// parse comma separated portsifstrings.Contains(port,","){ports:=strings.Split(port,",")portsInt:=[]uint16{}for_,p:=rangeports{portInt,err:=strconv.Atoi(p)iferr==nil&&portInt>=1&&portInt<=65535{portsInt=append(portsInt,uint16(portInt))}}returnportsInt}// parse single portportInt,_:=strconv.Atoi(port)ifportInt<1||portInt>65535{return[]uint16{}}return[]uint16{uint16(portInt)}}funccryptoIntN(nint)int{ifn<=0{return0}val,err:=rand.Int(rand.Reader,big.NewInt(int64(n)))iferr!=nil{return0}returnint(val.Int64())}funcgetPortFromPorts(ports[]uint16)uint16{iflen(ports)==0{return0}returnports[cryptoIntN(len(ports))]}// sleepDuration returns the duration between packets based on the packets per second// with a jitter in percent of the sleep durationfuncsleepDuration(pps,jitterint)time.Duration{duration:=time.Second/time.Duration(pps)jitterDuration:=time.Duration(jitter)*duration/100returnduration+jitterDuration-time.Duration(cryptoIntN(int(2*jitterDuration)))}funcmain(){ip:=flag.String("ip","","IP address to send packets to")pps:=flag.Int("pps",2,"Packets per second")jitter:=flag.Int("jitter",30,"in percent of the sleep duration")port:=flag.String("port","1-65535","Port to send packets to")icmpChance:=flag.Int("icmp-chance",180,"Chance to send ICMP packets (0-10000)")udpChance:=flag.Int("udp-chance",822,"Chance to send UDP packets (0-10000)")flag.Parse()// validate flagsif*ip==""{fmt.Println("IP address is required")flag.PrintDefaults()os.Exit(1)}if*pps<=0{fmt.Println("Packets per second must be greater than 0")flag.PrintDefaults()os.Exit(1)}if*jitter<0||*jitter>100{fmt.Println("Jitter must be between 0 and 100")flag.PrintDefaults()os.Exit(1)}if*port==""{fmt.Println("Port is required")flag.PrintDefaults()os.Exit(1)}if*icmpChance<0||*icmpChance>10000{fmt.Println("ICMP chance must be between 0 and 10000")flag.PrintDefaults()os.Exit(1)}if*udpChance<0||*udpChance>10000{fmt.Println("UDP chance must be between 0 and 10000")flag.PrintDefaults()os.Exit(1)}// parse portsports:=parsePort(*port)// send packetsfor{r:=cryptoIntN(10000)ifr<*icmpChance{sendICMP(*ip)}elseifr<*udpChance+*icmpChance{sendUDP(*ip,getPortFromPorts(ports))}else{sendTCPSYN(*ip,getPortFromPorts(ports))}time.Sleep(sleepDuration(*pps,*jitter))}}