Skip to content

Instantly share code, notes, and snippets.

@porjo
Created February 11, 2019 00:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save porjo/f1e6b79af77893ee71e857dfba2f8e9a to your computer and use it in GitHub Desktop.
Save porjo/f1e6b79af77893ee71e857dfba2f8e9a 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