-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnet.go
38 lines (34 loc) · 965 Bytes
/
net.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
package pgo
import (
"encoding/binary"
"errors"
"net"
)
// IP2long converts a string containing an (IPv4) Internet Protocol dotted address into a long integer
func IP2long(ipAddr string) (uint32, error) {
ip := net.ParseIP(ipAddr)
if ip == nil {
return 0, errors.New("wrong ipAddr format")
}
ip = ip.To4()
return binary.BigEndian.Uint32(ip), nil
}
// Long2ip converts an long integer address into a string in (IPv4) Internet standard dotted format
func Long2ip(ipLong uint32) string {
ipByte := make([]byte, 4)
binary.BigEndian.PutUint32(ipByte, ipLong)
ip := net.IP(ipByte)
return ip.String()
}
// GetMxrr Get MX records corresponding to a given Internet host name
// Returns TRUE if any records are found; returns FALSE if no records were found or if an error occurred
func GetMxrr(domain string) (isMx bool, mxs []*net.MX, err error) {
mxs, err = net.LookupMX(domain)
if err != nil {
return
}
if len(mxs) > 0 {
isMx = true
}
return
}