-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
635 lines (542 loc) · 19.4 KB
/
main.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
/*
nftables-api - add an ip to local nftables blocklists
The MIT License (MIT)
Copyright (c) 2025 Fred Posner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Example build commands:
GOOS=linux GOARCH=amd64 go build -o nftables-api
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o nftables-api
GOOS=linux GOARCH=arm GOARM=7 go build -o nftables-api-pi
*/
package main
import (
"errors"
"flag"
"fmt"
"io"
"log"
"net"
"net/http"
"os"
"runtime"
"github.com/apiban/nftlib"
"github.com/palner/pgrtools/pgparse"
"github.com/tidwall/sjson"
)
var (
apiPort string
setName string
logFile string
logFileLine bool
logLicense bool
useipv6 bool
)
func init() {
flag.StringVar(&apiPort, "port", "8084", "port to listen on")
flag.StringVar(&apiPort, "p", "8084", "port to listen on")
flag.StringVar(&logFile, "log", "/var/log/nftables-api.log", "location of log file or - for stdout")
flag.StringVar(&logFile, "l", "/var/log/nftables-api.log", "location of log file or - for stdout")
flag.StringVar(&setName, "setname", "APIBANLOCAL", "set name for entries")
flag.StringVar(&setName, "s", "APIBANLOCAL", "set name for entries")
flag.BoolVar(&logFileLine, "logextra", false, "add filename to log")
flag.BoolVar(&logFileLine, "x", false, "add filename to log")
flag.BoolVar(&logLicense, "license", false, "print license in log")
flag.BoolVar(&logLicense, "c", false, "print license in log")
flag.BoolVar(&useipv6, "ipv6", true, "use ipv6 (default is true)")
flag.BoolVar(&useipv6, "i", true, "use ipv6 (default is true)")
}
func main() {
// get flags
flag.Parse()
// Open our Log
if logFile != "-" && logFile != "stdout" {
lf, err := os.OpenFile(logFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
log.Panic(err)
fmt.Fprintf(os.Stderr, "error: %v\n", err)
runtime.Goexit()
}
defer lf.Close()
if logFileLine {
log.SetFlags(log.Lshortfile | log.LstdFlags)
} else {
log.SetFlags(log.LstdFlags)
}
log.SetOutput(lf)
}
InitLog()
router := http.NewServeMux()
router.HandleFunc("GET /add/{ipaddress}", addIPAddress)
router.HandleFunc("GET /addip/{ipaddress}", addIPAddress)
router.HandleFunc("GET /block/{ipaddress}", addIPAddress)
router.HandleFunc("GET /blockip/{ipaddress}", addIPAddress)
router.HandleFunc("GET /flush", flushSet)
router.HandleFunc("GET /flushset", flushSet)
router.HandleFunc("GET /remove/{ipaddress}", removeIPAddress)
router.HandleFunc("GET /removeip/{ipaddress}", removeIPAddress)
router.HandleFunc("GET /unblock/{ipaddress}", removeIPAddress)
router.HandleFunc("GET /unblockip/{ipaddress}", removeIPAddress)
router.HandleFunc("DELETE /", jsonHandleAddress)
router.HandleFunc("POST /", jsonHandleAddress)
router.HandleFunc("PUT /", jsonHandleAddress)
router.HandleFunc("GET /", listIPAddresses)
log.Print("[+] starting http server")
http.ListenAndServe("0.0.0.0:"+apiPort, router)
}
func addIPAddress(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
ipaddress := r.PathValue("ipaddress")
log.Println("[o] received addIPAddress request", ipaddress)
ipType, err := checkIPAddressv4(ipaddress)
if err != nil {
log.Println("[x]", ipaddress, "is not a valid ip address")
JSONHandleError(w, r, "aIP01", err.Error(), 400)
return
}
setDetails, err := NftCheckSet(setName)
if err != nil {
log.Println("[x] check set error:", err.Error())
JSONHandleError(w, r, "aIP02", err.Error(), 500)
return
}
if ipType == "ipv6" && !useipv6 {
log.Println("[x] cannot use ipv6")
JSONHandleError(w, r, "aIP03", "unable to use ipv6 address", 403)
return
}
if ipType == "ipv6" {
setDetails, err = nftlib.NftListSet(setName + "v6")
if err != nil {
log.Println("[x] cannot find ipv6 chain", err.Error())
JSONHandleError(w, r, "aIP04", err.Error(), 500)
return
}
}
err = nftlib.NftAddSetElement(setDetails, ipaddress)
if err != nil {
log.Println("[x] adding set element failed", err.Error())
JSONHandleError(w, r, "aIP05", err.Error(), 500)
return
}
log.Println("[+] added / blocked:", ipaddress)
jsonresp, _ := sjson.Set("", "status", "ok")
jsonresp, _ = sjson.Set(jsonresp, "ipaddress", ipaddress)
jsonresp, _ = sjson.Set(jsonresp, "details", "added to set "+setDetails.Set)
io.WriteString(w, jsonresp+"\n")
}
func checkIPAddress(ip string) bool {
if net.ParseIP(ip) == nil {
return false
} else {
return true
}
}
func checkIPAddressv4(ip string) (string, error) {
if net.ParseIP(ip) == nil {
return "err", errors.New("Not an IP address")
}
for i := 0; i < len(ip); i++ {
switch ip[i] {
case '.':
return "ipv4", nil
case ':':
return "ipv6", nil
}
}
return "err", errors.New("unknown error")
}
func flushSet(w http.ResponseWriter, r *http.Request) {
log.Println("[o] flush request received")
setDetails, err := NftCheckSet(setName)
if err != nil {
log.Println("[x] set check failed:", err.Error())
JSONHandleError(w, r, "fS00", err.Error(), 500)
return
}
err = nftlib.NftFlushSet(setDetails)
if err != nil {
log.Println("[x] flush set", setDetails.Set, "failed:", err.Error())
JSONHandleError(w, r, "fS01", err.Error(), 500)
return
}
if useipv6 {
setDetails, err = nftlib.NftListSet(setName + "v6")
if err != nil {
log.Println("[x] cannot find ipv6 chain", err.Error())
JSONHandleError(w, r, "fS02", err.Error(), 500)
return
}
err = nftlib.NftFlushSet(setDetails)
if err != nil {
log.Println("[x] flush set", setDetails.Set, "failed:", err.Error())
JSONHandleError(w, r, "fS03", err.Error(), 500)
return
}
}
log.Println("[+] flushed")
jsonresp, _ := sjson.Set("", "status", "ok")
jsonresp, _ = sjson.Set(jsonresp, "details", "flushed set(s)")
io.WriteString(w, jsonresp+"\n")
}
func InitLog() {
log.Print("-> [o] Starting nftables-api")
if logLicense {
log.Print(" --- ")
log.Print("The MIT License (MIT)")
log.Print(" ")
log.Print("Copyright (c) 2025 Fred Posner")
log.Print(" ")
log.Print("Permission is hereby granted, free of charge, to any person obtaining a copy")
log.Print("of this software and associated documentation files (the \"Software\"), to deal")
log.Print("in the Software without restriction, including without limitation the rights")
log.Print("to use, copy, modify, merge, publish, distribute, sublicense, and/or sell")
log.Print("copies of the Software, and to permit persons to whom the Software is")
log.Print("furnished to do so, subject to the following conditions:")
log.Print(" ")
log.Print("The above copyright notice and this permission notice shall be included in all")
log.Print("copies or substantial portions of the Software.")
log.Print(" ")
log.Print("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR")
log.Print("IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,")
log.Print("FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE")
log.Print("AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER")
log.Print("LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,")
log.Print("OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE")
log.Print("SOFTWARE.")
log.Print(" --- ")
} else {
log.Print("** Copyright (C) 2025 Fred Posner / The Palner Group, Inc.")
log.Print("** This program comes with ABSOLUTELY NO WARRANTY;")
log.Print("** This is free software, and you are welcome to redistribute it under certain conditions")
log.Print("** See LICENSE (on github or via -c --license flag) for details.")
}
log.Println("-> [.] Listening on port:", apiPort)
log.Println("-> [.] Log extra", logFileLine)
log.Println("-> [.] nftables set", setName)
}
func jsonHandleAddress(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
var handleType string
switch r.Method {
case "DELETE":
handleType = "delete"
case "PUT":
case "POST":
default:
handleType = "add"
}
log.Println("[o] received jsonHandleAddress request via method", handleType)
requiredfields := []string{"ipaddress"}
keyVal, err := pgparse.ParseBodyFields(r, requiredfields)
if err != nil {
log.Println("[x] jsonHandleAddress - errors occured:", err)
JSONHandleError(w, r, "jH001", err.Error(), 400)
return
}
log.Println("[.] ipaddress", keyVal["ipaddress"])
ipType, err := checkIPAddressv4(keyVal["ipaddress"])
if err != nil {
log.Println("[x]", keyVal["ipaddress"], "is not a valid ip address")
JSONHandleError(w, r, "jH002", err.Error(), 400)
return
}
setDetails, err := NftCheckSet(setName)
if err != nil {
log.Println("[x] check set error:", err.Error())
JSONHandleError(w, r, "jH003", err.Error(), 500)
return
}
if ipType == "ipv6" && !useipv6 {
log.Println("[x] cannot use ipv6")
JSONHandleError(w, r, "jh004", "unable to use ipv6 address", 403)
return
}
if ipType == "ipv6" {
setDetails, err = nftlib.NftListSet(setName + "v6")
if err != nil {
log.Println("[x] cannot find ipv6 chain", err.Error())
JSONHandleError(w, r, "jh005", err.Error(), 500)
return
}
}
var handleErr error
if handleType == "add" {
handleErr = nftlib.NftAddSetElement(setDetails, keyVal["ipaddress"])
} else if handleType == "delete" {
handleErr = nftlib.NftDelSetElement(setDetails, keyVal["ipaddress"])
}
if handleErr != nil {
log.Println("[x] updating set element failed", err.Error())
JSONHandleError(w, r, "jh006", err.Error(), 500)
return
}
log.Println("[+] added / blocked:", keyVal["ipaddress"])
jsonresp, _ := sjson.Set("", "status", "ok")
jsonresp, _ = sjson.Set(jsonresp, "ipaddress", keyVal["ipaddress"])
jsonresp, _ = sjson.Set(jsonresp, "details", "set "+setDetails.Set)
io.WriteString(w, jsonresp+"\n")
}
func JSONHandleError(w http.ResponseWriter, r *http.Request, errCode string, errDesc string, httpCode int64) {
log.Println("[JSONHandleError]", httpCode, errCode, errDesc)
w.Header().Set("Content-Type", "application/json")
httpJson, _ := sjson.Set("", "status", httpCode)
httpJson, _ = sjson.Set(httpJson, "error", errCode)
httpJson, _ = sjson.Set(httpJson, "details", errDesc)
switch httpCode {
case 400:
w.WriteHeader(http.StatusBadRequest)
case 403:
w.WriteHeader(http.StatusForbidden)
case 404:
w.WriteHeader(http.StatusNotFound)
case 408:
w.WriteHeader(http.StatusRequestTimeout)
case 429:
w.WriteHeader(http.StatusTooManyRequests)
case 500:
w.WriteHeader(http.StatusInternalServerError)
case 503:
w.WriteHeader(http.StatusServiceUnavailable)
default:
w.WriteHeader(http.StatusBadRequest)
}
io.WriteString(w, httpJson+"\n")
}
func NftAddSet(setname string) error {
log.Println("** Attempting to add set and rules")
log.Println("[-] finding input chains")
inputChains, err := nftlib.NftGetInputChains()
if err != nil {
log.Println("[x] error finding input chain:", err.Error())
return errors.New("error finding an input chain")
}
log.Println("[.] found", inputChains)
chainDetails, err := nftlib.NftGetChainDetails(inputChains[0])
if err != nil {
log.Println("[x] error finding input chain details:", err.Error())
return errors.New("error getting input chain details")
}
log.Println("[.] creating set", setname, "in", chainDetails.Table, chainDetails.Chain)
err = nftlib.NftAddSet(chainDetails, setname)
if err != nil {
log.Println("[x] unable to create set:", err.Error())
return errors.New("unable to create set")
}
log.Println("[.] creating input rule", setname, "in", chainDetails.Table, chainDetails.Chain)
err = nftlib.NftAddSetRuleInput(chainDetails, setname)
if err != nil {
log.Println("[*] unable to create input rule:", err.Error())
log.Println("[*] input rule failed. Set created though... continuing.")
log.Println("[*] *** PLEASE MANUALLY CREATE A RULE FOR THE", setname, "SET")
}
log.Println("[-] finding output chains")
outputchains, err := nftlib.NftGetOutputChains()
if err != nil {
log.Println("[x] error finding output chain:", err.Error())
return nil
}
log.Println("[.] found", outputchains)
chainDetails, err = nftlib.NftGetChainDetails(outputchains[0])
if err != nil {
log.Println("[x] error finding output chain details:", err.Error())
return nil
}
log.Println("[.] creating output rule", setname, "in", chainDetails.Table, chainDetails.Chain)
err = nftlib.NftAddSetRuleOutput(chainDetails, setname)
if err != nil {
log.Println("[*] unable to create output rule:", err.Error())
log.Println("[*] output rule failed. Set created though... continuing.")
log.Println("[*] *** PLEASE MANUALLY CREATE A RULE FOR THE", setname, "SET")
}
return nil
}
func NftAddv6Set(setname string) error {
log.Println("** Attempting to add ipv6 set and rules")
log.Println("[-] finding input chains")
inputChains, err := nftlib.NftGetInputChains()
if err != nil {
log.Println("[x] error finding input chain:", err.Error())
return errors.New("error finding an input chain")
}
log.Println("[.] found", inputChains)
chainDetails, err := nftlib.NftGetChainDetails(inputChains[0])
if err != nil {
log.Println("[x] error finding input chain details:", err.Error())
return errors.New("error getting input chain details")
}
if chainDetails.Family != "inet" {
log.Println("[x] error:", chainDetails.Family, "does not support ipv6.")
useipv6 = false
return errors.New("chain does not support ipv6")
}
log.Println("[.] creating set", setname, "in", chainDetails.Table, chainDetails.Chain)
err = nftlib.NftAddv6Set(chainDetails, setname)
if err != nil {
log.Println("[x] unable to create set:", err.Error())
useipv6 = false
return errors.New("unable to create set")
}
log.Println("[.] creating input rule", setname, "in", chainDetails.Table, chainDetails.Chain)
err = nftlib.NftAddSetRulev6Input(chainDetails, setname)
if err != nil {
log.Println("[*] unable to create input rule:", err.Error())
log.Println("[*] input rule failed. Set created though... continuing.")
log.Println("[*] *** PLEASE MANUALLY CREATE A RULE FOR THE", setname, "SET")
}
log.Println("[-] finding output chains")
outputchains, err := nftlib.NftGetOutputChains()
if err != nil {
log.Println("[x] error finding output chain:", err.Error())
return nil
}
log.Println("[.] found", outputchains)
chainDetails, err = nftlib.NftGetChainDetails(outputchains[0])
if err != nil {
log.Println("[x] error finding output chain details:", err.Error())
return nil
}
log.Println("[.] creating output rule", setname, "in", chainDetails.Table, chainDetails.Chain)
err = nftlib.NftAddSetRulev6Output(chainDetails, setname)
if err != nil {
log.Println("[*] unable to create output rule:", err.Error())
log.Println("[*] output rule failed. Set created though... continuing.")
log.Println("[*] *** PLEASE MANUALLY CREATE A RULE FOR THE", setname, "SET")
}
return nil
}
func NftCheckSet(setname string) (nftlib.NFTABLES, error) {
currentSet, err := nftlib.NftListSet(setname)
if err != nil {
log.Println("[x] Cannot verify nftables set:", setname)
log.Println("[x] error:", err.Error())
log.Println("[.] trying to create set")
seterr := NftAddSet(setname)
if seterr != nil {
log.Println("[x] cannot create set", setname, ":", err.Error())
return currentSet, errors.New("cannot create set")
}
currentSet, err = nftlib.NftListSet(setname)
if err != nil {
log.Println("[x]", err.Error())
log.Println("[x] Still cannot verify nftables set:", setname)
return currentSet, errors.New("cannot verify set exists")
}
log.Println("[+]", currentSet.Set, "verified")
}
log.Println("[.]", setname, "exists. Currently has", len(currentSet.Elements), "elements.")
if useipv6 {
v6set := setname + "v6"
_, err := nftlib.NftListSet(v6set)
if err != nil {
log.Println("[x] Cannot verify nftables set:", v6set)
log.Println("[x] error:", err.Error())
log.Println("[.] trying to create set")
seterr := NftAddv6Set(v6set)
if seterr != nil {
log.Println("[x] cannot create set", v6set, ":", err.Error())
useipv6 = false
} else {
_, err = nftlib.NftListSet(v6set)
if err != nil {
log.Println("[x]", err.Error())
log.Println("[x] Still cannot verify nftables set:", v6set)
useipv6 = false
} else {
log.Println("[+]", currentSet.Set, "verified")
}
}
}
}
return currentSet, nil
}
func removeIPAddress(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
ipaddress := r.PathValue("ipaddress")
log.Println("[o] received removeIPAddress request", ipaddress)
ipType, err := checkIPAddressv4(ipaddress)
if err != nil {
log.Println("[x]", ipaddress, "is not a valid ip address")
JSONHandleError(w, r, "rIP01", err.Error(), 400)
return
}
setDetails, err := NftCheckSet(setName)
if err != nil {
log.Println("[x] check set error:", err.Error())
JSONHandleError(w, r, "rIP02", err.Error(), 500)
return
}
if ipType == "ipv6" && !useipv6 {
log.Println("[x] cannot use ipv6")
JSONHandleError(w, r, "rIP03", "unable to use ipv6 address", 403)
return
}
if ipType == "ipv6" {
setDetails, err = nftlib.NftListSet(setName + "v6")
if err != nil {
log.Println("[x] cannot find ipv6 chain", err.Error())
JSONHandleError(w, r, "rIP04", err.Error(), 500)
return
}
}
err = nftlib.NftDelSetElement(setDetails, ipaddress)
if err != nil {
log.Println("[x] removing set element failed", err.Error())
JSONHandleError(w, r, "rIP05", err.Error(), 500)
return
}
log.Println("[+] removed / unblocked:", ipaddress)
jsonresp, _ := sjson.Set("", "status", "ok")
jsonresp, _ = sjson.Set(jsonresp, "ipaddress", ipaddress)
jsonresp, _ = sjson.Set(jsonresp, "details", "removed from set "+setDetails.Set)
io.WriteString(w, jsonresp+"\n")
}
func NftListv4(setname string) ([]string, error) {
currentSet, err := nftlib.NftListSet(setname)
if err != nil {
return []string{}, err
}
return currentSet.Elements, nil
}
func NftListv6(setname string) ([]string, error) {
if useipv6 {
v6set := setname + "v6"
currentSet, err := nftlib.NftListSet(v6set)
if err != nil {
return []string{}, err
}
return currentSet.Elements, nil
}
return []string{}, nil
}
func listIPAddresses(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
log.Println("[o] received listIPAddresses request")
v4set, errv4 := NftListv4(setName)
v6set, errv6 := NftListv6(setName)
if errv4 != nil {
log.Println("[x] ipv4 set error:", errv4.Error())
}
if errv6 != nil {
log.Println("[x] ipv6 set error:", errv6.Error())
}
log.Println("ipv4", v4set)
log.Println("ipv6", v6set)
jsonresp, _ := sjson.Set("", "status", "ok")
jsonresp, _ = sjson.Set(jsonresp, "ipv4", v4set)
jsonresp, _ = sjson.Set(jsonresp, "ipv6", v6set)
io.WriteString(w, jsonresp+"\n")
}