This repository has been archived by the owner on Apr 7, 2024. It is now read-only.
/
list.go
93 lines (83 loc) · 1.78 KB
/
list.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
package main
/*
* list.go
* List scanned hosts
* By J. Stuart McMurray
* Created 20160706
* Last Modified 20160706
*/
import (
"fmt"
"io"
"net"
"net/http"
"sort"
"github.com/boltdb/bolt"
)
/* List returns the list of scanned hosts */
func listScanned(w http.ResponseWriter, req *http.Request) {
/* Get the requestor's address */
rip, _, err := net.SplitHostPort(req.RemoteAddr)
if nil != err {
w.WriteHeader(http.StatusInternalServerError)
io.WriteString(w, err.Error())
return
}
/* List of IP Addresses */
ips := make([]string, 0)
/* Get the list of addresses */
if err := DB.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(RESBUCKET))
/* Iterate over all the keys */
c := bucket.Cursor()
for k, _ := c.First(); k != nil; k, _ = c.Next() {
/* []byte -> String -> []byte -> string */
ip := net.ParseIP(string(k))
if ip4 := ip.To4(); nil != ip4 {
ip = ip4
}
ips = append(ips, string(ip))
}
return nil
}); nil != err {
w.WriteHeader(http.StatusInternalServerError)
io.WriteString(w, err.Error())
return
}
/* Sort list of IPs */
sort.Strings(ips)
/* Return them */
if _, err := io.WriteString(
w,
`<!DOCTYPE HTML>
<HEAD>
<TITLE>CGIScanned</TITLE>
<STYLE TYPE="text/css"><!--
body {
background-color: white;
color: black;
font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif;
}
--></STYLE>
</HEAD>
<BODY>
<H1>Scanned IP Addresses</H1>
<P>
`); nil != err {
return
}
for _, ip := range ips {
a := net.IP(ip).String()
if _, err := w.Write([]byte(fmt.Sprintf(
"<A HREF=\"%v/res/%v\">%v</A><BR>\n",
URLPATH,
a,
a,
))); nil != err {
return
}
}
io.WriteString(w, "</P>\n</BODY>\n</HTML>\n")
debug("%v Sent list of %v address links", rip, len(ips))
}
/* TODO: Templates? :( */