forked from njern/gonexmo
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathip.go
More file actions
34 lines (28 loc) · 670 Bytes
/
ip.go
File metadata and controls
34 lines (28 loc) · 670 Bytes
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
package nexmo
import "net"
// IP's sourced from https://help.nexmo.com/entries/23181071-Source-IP-subnet-for-incoming-traffic-in-REST-API
var masks = []string{
"174.37.245.32/29",
"174.36.197.192/28",
"173.193.199.16/28",
"119.81.44.0/28",
}
var subnets []net.IPNet
func init() {
subnets = make([]net.IPNet, len(masks))
for i, mask := range masks {
_, net, _ := net.ParseCIDR(mask)
subnets[i] = *net
}
}
// IsTrustedIP returns true if the provided IP address came from
// a trusted Nexmo server.
func IsTrustedIP(ipStr string) bool {
ip := net.ParseIP(ipStr)
for _, net := range subnets {
if net.Contains(ip) {
return true
}
}
return false
}