-
Notifications
You must be signed in to change notification settings - Fork 1
/
dailyscan.go
55 lines (50 loc) · 1.25 KB
/
dailyscan.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
package Usom
import (
"context"
"encoding/xml"
"net"
"time"
"github.com/astaxie/beego/httplib"
)
func Scandaily(masks []string, speed int) map[string]interface{} {
list := []Pong{}
scanned := []Pong{}
var s, _ = time.Parse("2006-01-02 15:04:05", time.Now().Local().Format("2006-01-02 15:04:05"))
var lastDay = s.Unix() - 86400
usomUrlList, _ := httplib.Get("https://www.usom.gov.tr/url-list.xml").Bytes()
xml.Unmarshal(usomUrlList, &t)
jobs := make(chan string)
done := make(chan bool)
go func() {
for {
j, more := <-jobs
if more {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(speed)*time.Millisecond)
ipaddr, _ := net.DefaultResolver.LookupHost(ctx, Cleanurl(j))
if ipaddr != nil {
for _, v := range ipaddr {
scanned = append(scanned, Pong{IP: v, Hostname: Cleanurl(j)})
if Isinside(v, masks) != nil {
list = append(list, Pong{IP: v, Hostname: Cleanurl(j)})
}
}
}
} else {
done <- true
return
}
}
}()
for _, url := range t.UrlList.UrlInfo {
p, _ := time.Parse("2006-01-02 15:04:05", url.Date)
if p.Unix() > lastDay {
jobs <- url.Url
}
}
close(jobs)
<-done
e := make(map[string]interface{})
e["scanned"] = scanned
e["results"] = list
return e
}