package main
import (
"fmt"
"math"
"net"
"encoding/binary"
)
func main() {
var ii uint32 = 0
for i:=1; i<33; i++ {
ii += uint32(math.Pow(2, float64(32-i)));
fmt.Print(i, " ", long2ip(ii), " ", ii, "\n")
}
}
func ip2long(ipstr string) uint32 {
ip := net.ParseIP(ipstr)
if ip == nil { return 0 }
return binary.BigEndian.Uint32(ip.To4())
}
func long2ip(ipLong uint32) string {
ipByte := make([]byte, 4)
binary.BigEndian.PutUint32(ipByte, ipLong)
return net.IP(ipByte).String()
}
沒有留言:
張貼留言