Skip to content

Instantly share code, notes, and snippets.

@gglluukk
Forked from porjo/random_ip.go
Created November 15, 2023 23:04
Show Gist options
  • Save gglluukk/b5b6d301af43f8197d0404d05f6a8815 to your computer and use it in GitHub Desktop.
Save gglluukk/b5b6d301af43f8197d0404d05f6a8815 to your computer and use it in GitHub Desktop.
Generate random IPs with Go
package main
import (
"encoding/binary"
"fmt"
"math/rand"
"net"
)
func main() {
buf := make([]byte, 4)
for i := 0; i < 10; i++ {
ip := rand.Uint32()
binary.LittleEndian.PutUint32(buf, ip)
fmt.Printf("%s\n", net.IP(buf))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment