You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
631 B
35 lines
631 B
package model |
|
|
|
import "net" |
|
|
|
const ( |
|
TypeIOS = "ios" |
|
TypeAndriod = "android" |
|
) |
|
|
|
// InetAtoN conver ip addr to uint32. |
|
func InetAtoN(s string) (sum uint32) { |
|
ip := net.ParseIP(s) |
|
if ip == nil { |
|
return |
|
} |
|
ip = ip.To4() |
|
if ip == nil { |
|
return |
|
} |
|
sum += uint32(ip[0]) << 24 |
|
sum += uint32(ip[1]) << 16 |
|
sum += uint32(ip[2]) << 8 |
|
sum += uint32(ip[3]) |
|
return sum |
|
} |
|
|
|
// InetNtoA conver uint32 to ip addr. |
|
func InetNtoA(sum uint32) string { |
|
ip := make(net.IP, net.IPv4len) |
|
ip[0] = byte((sum >> 24) & 0xFF) |
|
ip[1] = byte((sum >> 16) & 0xFF) |
|
ip[2] = byte((sum >> 8) & 0xFF) |
|
ip[3] = byte(sum & 0xFF) |
|
return ip.String() |
|
}
|
|
|