forked from fiorix/freegeoip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreegeoip.go
820 lines (746 loc) · 17.7 KB
/
freegeoip.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
// Copyright 2009-2014 Alexandre Fiori
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Web server of freegeoip.net
package main
import (
"database/sql"
"encoding/binary"
"encoding/json"
"encoding/xml"
"expvar"
"flag"
"fmt"
"io"
"log"
"math/rand"
"net"
"net/http"
"os"
"os/signal"
"path/filepath"
"runtime"
"runtime/pprof"
"strconv"
"strings"
"sync"
"syscall"
"time"
"github.com/fiorix/go-redis/redis"
"github.com/fiorix/go-web/httpxtra"
"github.com/gorilla/context"
// SQLite driver.
// _ "github.com/mattn/go-sqlite3"
_ "code.google.com/p/gosqlite/sqlite3"
)
var (
collectStats bool
outputCount = expvar.NewMap("Output") // json, xml or csv
statusCount = expvar.NewMap("Status") // 200, 403, 404, etc
protocolCount = expvar.NewMap("Protocol") // HTTP or HTTPS
dns *dnsHandler
)
func main() {
flLog := flag.String("l", "", "log to file instead of stderr")
flConfig := flag.String("c", "freegeoip.conf", "set config file")
flProfile := flag.Bool("profile", false, "run cpu and mem profiler")
flag.Parse()
if *flProfile {
runProfile()
}
cf, err := loadConfig(*flConfig)
if err != nil {
log.Fatal(err)
}
collectStats = cf.Debug
if cf.DNS.Enabled {
t, err := time.ParseDuration(cf.DNS.Timeout)
if err != nil {
log.Fatal("Invalid DNS timeout:", err)
}
dns = &dnsHandler{
Timeout: t,
MaxConcurrent: cf.DNS.MaxConcurrent,
}
}
if *flLog != "" {
setLog(*flLog)
}
runtime.GOMAXPROCS(runtime.NumCPU())
log.Printf("FreeGeoIP server starting. debug=%t", cf.Debug)
if cf.Debug && len(cf.DebugSrv) > 0 {
go func() {
// server for expvar's /debug/vars only
log.Printf("Starting DEBUG server on tcp/%s", cf.DebugSrv)
log.Fatal(http.ListenAndServe(cf.DebugSrv, nil))
}()
}
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(http.Dir(cf.DocumentRoot)))
lh := lookupHandler(cf)
mux.HandleFunc("/csv/", lh)
mux.HandleFunc("/xml/", lh)
mux.HandleFunc("/json/", lh)
for _, c := range cf.Listen {
go runServer(mux, c)
}
select {}
}
func lookupHandler(cf *configFile) http.HandlerFunc {
db := openDB(cf)
var rl rateLimiter
if cf.Limit.MaxRequests > 0 {
if len(cf.Redis) > 0 {
rl = new(redisQuota)
log.Printf("Using redis to manage quota: %s", cf.Redis)
} else {
rl = new(mapQuota)
log.Printf("Using internal map to manage quota.")
}
rl.Setup(cf)
}
return func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
w.Header().Set("Access-Control-Allow-Origin", "*")
handleRequest(cf, db, rl, w, r)
case "OPTIONS":
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Methods", "GET")
w.Header().Set("Access-Control-Allow-Headers", "X-Requested-With")
w.WriteHeader(200)
default:
w.Header().Set("Allow", "GET, OPTIONS")
http.Error(w, http.StatusText(405), 405)
}
}
}
func handleRequest(
cf *configFile,
db *DB,
rl rateLimiter,
w http.ResponseWriter,
r *http.Request,
) {
// If xheaders is enabled, RemoteAddr might be a copy of
// the X-Real-IP or X-Forwarded-For HTTP headers, which
// can be a comma separated list of IPs. In this case,
// only the first IP in the list is used.
if strings.Index(r.RemoteAddr, ",") > 0 {
r.RemoteAddr = strings.SplitN(r.RemoteAddr, ",", 2)[0]
}
// Parse remote address.
var ip net.IP
if sIP, _, err := net.SplitHostPort(r.RemoteAddr); err != nil {
ip = net.ParseIP(r.RemoteAddr) // Use X-Real-IP, etc
} else {
ip = net.ParseIP(sIP)
}
if ip == nil {
// This could be a misconfigured unix socket server.
context.Set(r, "log", "Invalid source IP: "+r.RemoteAddr)
http.Error(w, http.StatusText(500), 500)
return
}
// Convert remote IP to integer to check quota.
// IPv6 is not supported yet. See issue #21 for details.
nIP, err := ip2int(ip)
if err != nil {
context.Set(r, "log", err.Error())
http.Error(w, "IPv6 is not supported.", 501)
return
}
// Check quota.
if rl != nil {
var ok bool
if ok, err = rl.Ok(nIP); err != nil {
context.Set(r, "log", err.Error()) // redis err
http.Error(w, http.StatusText(503), 503)
return
} else if !ok {
// Over quota, soz :(
http.Error(w, http.StatusText(403), 403)
return
}
}
// Figure out the query: /fmt/{query} or /fmt/{nil}
// In case of {nil} we query the remote IP.
path := strings.SplitN(r.URL.Path, "/", 3)
if len(path) != 3 {
// This handler is for /fmt/ where fmt is json, xml or csv.
log.Fatal("Unexpected URL:", r.URL.Path)
}
// Process the query, if there's one.
if path[2] != "" {
// Allow to query by IP or hostname.
if ip = net.ParseIP(path[2]); ip == nil {
if dns == nil {
// DNS lookups not allowed.
http.Error(w, http.StatusText(404), 404)
return
}
if ip = dns.LookupHost(path[2]); ip == nil {
// DNS lookup failed, assume host not found.
http.Error(w, http.StatusText(404), 404)
return
}
}
nIP, err = ip2int(ip) // IPv6 fails here.
if err != nil {
context.Set(r, "log", err.Error())
http.Error(w, http.StatusText(404), 404)
return
}
}
// Query the db.
var record *geoipRecord
if record, err = db.Lookup(ip, nIP); err != nil {
http.NotFound(w, r)
return
}
// Write response.
switch path[1][0] {
case 'j':
if cb := r.FormValue("callback"); cb != "" {
w.Header().Set("Content-Type", "text/javascript")
record.JSONP(w, cb)
} else {
w.Header().Set("Content-Type", "application/json")
record.JSON(w)
}
case 'x':
w.Header().Set("Content-Type", "application/xml")
record.XML(w)
case 'c':
w.Header().Set("Content-Type", "application/csv")
record.CSV(w)
}
}
func runServer(mux *http.ServeMux, c *serverConfig) {
h := httpxtra.Handler{
Handler: mux,
XHeaders: c.XHeaders,
}
if c.Log {
h.Logger = httpLogger
}
s := http.Server{
Addr: c.Addr,
Handler: h,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
}
if c.KeyFile != "" && c.CertFile != "" {
log.Printf("Starting HTTPS server on tcp/%s "+
"log=%t xheaders=%t cert=%s key=%s",
c.Addr,
c.Log,
c.XHeaders,
c.CertFile,
c.KeyFile,
)
log.Fatal(s.ListenAndServeTLS(c.CertFile, c.KeyFile))
} else {
log.Printf("Starting HTTP server on tcp/%s "+
"log=%t xheaders=%t",
c.Addr,
c.Log,
c.XHeaders,
)
log.Fatal(httpxtra.ListenAndServe(s))
}
}
type dnsHandler struct {
Timeout time.Duration
MaxConcurrent int
mu sync.Mutex
count int
}
func (dh *dnsHandler) LookupHost(name string) (ip net.IP) {
c := make(chan net.IP, 1)
dh.mu.Lock()
if dh.count == dh.MaxConcurrent {
dh.mu.Unlock()
return
}
dh.count++
dh.mu.Unlock()
go func() {
addrs, err := net.LookupHost(name)
if err != nil {
c <- nil
} else if len(addrs) == 1 {
c <- net.ParseIP(addrs[0])
} else {
c <- net.ParseIP(addrs[rand.Intn(len(addrs)-1)])
}
}()
select {
case ip = <-c:
case <-time.After(dh.Timeout):
}
dh.mu.Lock()
defer dh.mu.Unlock()
dh.count--
return
}
type DB struct {
db *sql.DB
stmt *sql.Stmt
// cache
country map[string]string
region map[regionKey]string
city map[int]locationData
}
type regionKey struct {
CountryCode,
RegionCode string
}
type locationData struct {
CountryCode,
RegionCode,
CityName,
ZipCode string
Latitude,
Longitude float32
MetroCode,
AreaCode string
}
func openDB(cf *configFile) *DB {
var (
db DB
err error
)
if db.db, err = sql.Open("sqlite3", cf.IPDB.File); err != nil {
log.Fatal(err)
}
if _, err = db.db.Exec("PRAGMA cache_size=" + cf.IPDB.CacheSize); err != nil {
log.Fatal(err)
}
if db.stmt, err = db.db.Prepare(`
SELECT
loc_id
FROM
city_blocks
WHERE
ip_start <= ?
ORDER BY
ip_start DESC
LIMIT 1
`); err != nil {
log.Fatal(err)
}
st := time.Now()
db.loadCache()
log.Println("IPDB cached in", time.Since(st))
return &db
}
func (db *DB) loadCache() {
var wg sync.WaitGroup
wg.Add(3)
go db.loadCountries(&wg)
go db.loadRegions(&wg)
go db.loadCities(&wg)
wg.Wait()
}
func (db *DB) loadCountries(wg *sync.WaitGroup) {
defer wg.Done()
db.country = make(map[string]string)
row, err := db.db.Query(`
SELECT
country_code,
country_name
FROM
country_blocks
`)
if err != nil {
log.Fatal("Failed to load countries from db:", err)
}
defer row.Close()
var country_code, name string
for row.Next() {
if err = row.Scan(
&country_code,
&name,
); err != nil {
log.Fatal("Failed to load country from db:", err)
}
db.country[country_code] = name
}
}
func (db *DB) loadRegions(wg *sync.WaitGroup) {
defer wg.Done()
db.region = make(map[regionKey]string)
row, err := db.db.Query(`
SELECT
country_code,
region_code,
region_name
FROM
region_names
`)
if err != nil {
log.Fatal("Failed to load regions from db:", err)
}
defer row.Close()
var country_code, region_code, name string
for row.Next() {
if err = row.Scan(
&country_code,
®ion_code,
&name,
); err != nil {
log.Fatal("Failed to load region from db:", err)
}
db.region[regionKey{country_code, region_code}] = name
}
}
func (db *DB) loadCities(wg *sync.WaitGroup) {
defer wg.Done()
db.city = make(map[int]locationData)
row, err := db.db.Query("SELECT * FROM city_location")
if err != nil {
log.Fatal("Failed to load cities from db:", err)
}
defer row.Close()
var (
locId int
loc locationData
)
for row.Next() {
if err = row.Scan(
&locId,
&loc.CountryCode,
&loc.RegionCode,
&loc.CityName,
&loc.ZipCode,
&loc.Latitude,
&loc.Longitude,
&loc.MetroCode,
&loc.AreaCode,
); err != nil {
log.Fatal("Failed to load city from db:", err)
}
db.city[locId] = loc
}
}
func (db *DB) Lookup(ip net.IP, nIP uint32) (*geoipRecord, error) {
for _, net := range reservedIPs {
if net.Contains(ip) {
return &geoipRecord{
Ip: ip.String(),
CountryCode: "RD",
CountryName: "Reserved",
}, nil
}
}
var locId int
if err := db.stmt.QueryRow(nIP).Scan(&locId); err != nil {
return nil, err
}
return db.newRecord(&ip, locId), nil
}
func (db *DB) newRecord(ip *net.IP, locId int) *geoipRecord {
city, ok := db.city[locId]
if !ok {
return &geoipRecord{Ip: ip.String()}
}
return &geoipRecord{
Ip: ip.String(),
CountryCode: city.CountryCode,
CountryName: db.country[city.CountryCode],
RegionCode: city.RegionCode,
RegionName: db.region[regionKey{
city.CountryCode,
city.RegionCode,
}],
CityName: city.CityName,
ZipCode: city.ZipCode,
Latitude: city.Latitude,
Longitude: city.Longitude,
MetroCode: city.MetroCode,
AreaCode: city.AreaCode,
}
}
type geoipRecord struct {
XMLName xml.Name `json:"-" xml:"Response"`
Ip string `json:"ip"`
CountryCode string `json:"country_code"`
CountryName string `json:"country_name"`
RegionCode string `json:"region_code"`
RegionName string `json:"region_name"`
CityName string `json:"city" xml:"City"`
ZipCode string `json:"zipcode"`
Latitude float32 `json:"latitude"`
Longitude float32 `json:"longitude"`
MetroCode string `json:"metro_code"`
AreaCode string `json:"area_code"`
}
func (r *geoipRecord) JSON(w io.Writer) {
if collectStats {
outputCount.Add("json", 1)
}
json.NewEncoder(w).Encode(r)
}
func (r *geoipRecord) JSONP(w io.Writer, callback string) {
if collectStats {
outputCount.Add("json", 1)
}
w.Write([]byte(callback))
w.Write([]byte("("))
json.NewEncoder(w).Encode(r)
w.Write([]byte(");"))
}
func (r *geoipRecord) XML(w io.Writer) {
if collectStats {
outputCount.Add("xml", 1)
}
enc := xml.NewEncoder(w)
enc.Indent("", " ")
w.Write([]byte(xml.Header))
enc.Encode(r)
w.Write([]byte("\n"))
}
func (r *geoipRecord) CSV(w io.Writer) {
if collectStats {
outputCount.Add("csv", 1)
}
fmt.Fprintf(w, `"%s","%s","%s","%s","%s","%s","%s","%0.4f","%0.4f","%s","%s"`+"\r\n",
r.Ip,
r.CountryCode,
r.CountryName,
r.RegionCode,
r.RegionName,
r.CityName,
r.ZipCode,
r.Latitude,
r.Longitude,
r.MetroCode,
r.AreaCode,
)
}
type rateLimiter interface {
Setup(cf *configFile) // Initialize backend
Ok(ipkey uint32) (bool, error) // Returns true if under quota
}
// mapQuota implements the rateLimiter interface using a map as the backend.
type mapQuota struct {
cf *configFile
mu sync.Mutex
ip map[uint32]int
}
func (q *mapQuota) Setup(cf *configFile) {
q.cf = cf
q.ip = make(map[uint32]int)
}
func (q *mapQuota) Ok(ipkey uint32) (bool, error) {
q.mu.Lock()
defer q.mu.Unlock()
if n, ok := q.ip[ipkey]; ok {
if n < q.cf.Limit.MaxRequests {
q.ip[ipkey]++
return true, nil
}
return false, nil
}
q.ip[ipkey] = 1
go func() {
time.Sleep(time.Duration(q.cf.Limit.Expire) * time.Second)
q.mu.Lock()
defer q.mu.Unlock()
delete(q.ip, ipkey)
}()
return true, nil
}
// redisQuota implements the rateLimiter interface using Redis as the backend.
type redisQuota struct {
cf *configFile
rc *redis.Client
}
func (q *redisQuota) Setup(cf *configFile) {
redis.MaxIdleConnsPerAddr = 5000
q.cf = cf
q.rc = redis.New(cf.Redis...)
q.rc.Timeout = time.Duration(1500) * time.Millisecond
}
func (q *redisQuota) Ok(ipkey uint32) (bool, error) {
k := strconv.Itoa(int(ipkey)) // "numeric" key
if ns, err := q.rc.Get(k); err != nil {
return false, fmt.Errorf("redis get: %s", err)
} else if ns == "" {
if err = q.rc.SetEx(k, q.cf.Limit.Expire, "1"); err != nil {
return false, fmt.Errorf("redis setex: %s", err)
}
} else if n, _ := strconv.Atoi(ns); n < q.cf.Limit.MaxRequests {
if n, err = q.rc.Incr(k); err != nil {
return false, fmt.Errorf("redis incr: %s", err)
} else if n == 1 {
q.rc.Expire(k, q.cf.Limit.Expire)
}
} else {
return false, nil
}
return true, nil
}
func ip2int(ip net.IP) (uint32, error) {
ipv4 := ip.To4()
if ipv4 == nil {
return 0, fmt.Errorf("IP %s is not IPv4", ip.String())
}
return binary.BigEndian.Uint32(ipv4), nil
}
func runProfile() {
f, err := os.Create("freegeoip.cpu.prof")
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, os.Kill)
go func() {
<-sig
pprof.StopCPUProfile()
f.Close()
f, err = os.Create("freegeoip.mem.prof")
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)
os.Exit(0)
}()
}
func setLog(filename string) {
f := openLog(filename)
log.SetOutput(f)
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGHUP)
go func() {
// Recycle log file on SIGHUP.
var fb *os.File
for {
<-sigc
fb = f
f = openLog(filename)
log.SetOutput(f)
fb.Close()
}
}()
}
func openLog(filename string) *os.File {
f, err := os.OpenFile(
filename,
os.O_WRONLY|os.O_CREATE|os.O_APPEND,
0644,
)
if err != nil {
log.SetOutput(os.Stderr)
log.Fatal(err)
}
return f
}
func httpLogger(r *http.Request, created time.Time, status, bytes int) {
//fmt.Println(httpxtra.ApacheCommonLog(r, created, status, bytes))
var (
s, ip, msg string
err error
)
if r.TLS == nil {
s = "HTTP"
} else {
s = "HTTPS"
}
if ip, _, err = net.SplitHostPort(r.RemoteAddr); err != nil {
ip = r.RemoteAddr
}
if tmp := context.Get(r, "log"); tmp != nil {
msg = fmt.Sprintf(" (%s)", tmp)
context.Clear(r)
}
log.Printf("%s %d %s %q (%s) :: %d bytes in %s%s",
s,
status,
r.Method,
r.URL.Path,
ip,
bytes,
time.Since(created),
msg,
)
if collectStats {
protocolCount.Add(s, 1)
statusCount.Add(strconv.Itoa(status), 1)
}
}
type serverConfig struct {
Log bool `xml:"log,attr"`
XHeaders bool `xml:"xheaders,attr"`
Addr string `xml:"addr,attr"`
CertFile string
KeyFile string
}
type configFile struct {
XMLName xml.Name `xml:"Server"`
Debug bool `xml:"debug,attr"`
DebugSrv string `xml:"debugsrv,attr"`
DocumentRoot string
Listen []*serverConfig
DNS struct {
Enabled bool `xml:",attr"`
Timeout string `xml:",attr"`
MaxConcurrent int `xml:",attr"`
}
IPDB struct {
File string `xml:",attr"`
CacheSize string `xml:",attr"`
}
Limit struct {
MaxRequests int `xml:",attr"`
Expire int `xml:",attr"`
}
Redis []string `xml:"Redis>Addr"`
}
func loadConfig(filename string) (*configFile, error) {
var cf configFile
if fd, err := os.Open(filename); err != nil {
return nil, err
} else {
if err = xml.NewDecoder(fd).Decode(&cf); err != nil {
return nil, err
}
fd.Close()
}
// Make files' path relative to the config file's directory.
basedir := filepath.Dir(filename)
relativePath(basedir, &cf.IPDB.File)
relativePath(basedir, &cf.DocumentRoot)
for _, l := range cf.Listen {
relativePath(basedir, &l.CertFile)
relativePath(basedir, &l.KeyFile)
}
return &cf, nil
}
func relativePath(basedir string, filename *string) {
if *filename != "" && (*filename)[0] != '/' {
*filename = filepath.Join(basedir, *filename)
}
}
// http://en.wikipedia.org/wiki/Reserved_IP_addresses
var reservedIPs = []net.IPNet{
{net.IPv4(0, 0, 0, 0), net.IPv4Mask(255, 0, 0, 0)},
{net.IPv4(10, 0, 0, 0), net.IPv4Mask(255, 0, 0, 0)},
{net.IPv4(100, 64, 0, 0), net.IPv4Mask(255, 192, 0, 0)},
{net.IPv4(127, 0, 0, 0), net.IPv4Mask(255, 0, 0, 0)},
{net.IPv4(169, 254, 0, 0), net.IPv4Mask(255, 255, 0, 0)},
{net.IPv4(172, 16, 0, 0), net.IPv4Mask(255, 240, 0, 0)},
{net.IPv4(192, 0, 0, 0), net.IPv4Mask(255, 255, 255, 248)},
{net.IPv4(192, 0, 2, 0), net.IPv4Mask(255, 255, 255, 0)},
{net.IPv4(192, 88, 99, 0), net.IPv4Mask(255, 255, 255, 0)},
{net.IPv4(192, 168, 0, 0), net.IPv4Mask(255, 255, 0, 0)},
{net.IPv4(198, 18, 0, 0), net.IPv4Mask(255, 254, 0, 0)},
{net.IPv4(198, 51, 100, 0), net.IPv4Mask(255, 255, 255, 0)},
{net.IPv4(203, 0, 113, 0), net.IPv4Mask(255, 255, 255, 0)},
{net.IPv4(224, 0, 0, 0), net.IPv4Mask(240, 0, 0, 0)},
{net.IPv4(240, 0, 0, 0), net.IPv4Mask(240, 0, 0, 0)},
{net.IPv4(255, 255, 255, 255), net.IPv4Mask(255, 255, 255, 255)},
}