-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
106 lines (88 loc) · 3.04 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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
)
type Data struct {
AddrInfo AddrInfo `json:"AddrInfo"`
LastAdvertisement map[string]string `json:"LastAdvertisement"`
LastAdvertisementTime string `json:"LastAdvertisementTime"`
Publisher AddrInfo `json:"Publisher"`
ExtendedProviders map[string]interface{} `json:"ExtendedProviders"`
FrozenAt *string `json:"FrozenAt"`
}
type AddrInfo struct {
ID string `json:"ID"`
Addrs []string `json:"Addrs"`
}
func main() {
url := "https://cid.contact/providers"
resp, err := http.Get(url)
if err != nil {
fmt.Println("Error fetching data:", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading data:", err)
return
}
var data []Data
err = json.Unmarshal(body, &data)
if err != nil {
fmt.Println("Error parsing JSON:", err)
return
}
uniqueAddrs := make(map[string]struct{})
uniqueTCPAddrs := make(map[string]struct{})
uniqueWSAddrs := make(map[string]struct{})
uniqueHTTPSAddrs := make(map[string]struct{})
frozenCount := 0
adsWithin6Months := 0
sixMonthsAgo := time.Now().AddDate(0, -6, 0)
uniquePublisherIDs := make(map[string]struct{})
for _, entry := range data {
if _, exists := uniquePublisherIDs[entry.Publisher.ID]; !exists {
uniquePublisherIDs[entry.Publisher.ID] = struct{}{}
for _, publisherAddr := range entry.Publisher.Addrs {
uniqueAddrs[publisherAddr] = struct{}{}
if strings.Contains(publisherAddr, "tcp") && !strings.Contains(publisherAddr, "https") && !strings.Contains(publisherAddr, "wss") {
uniqueTCPAddrs[publisherAddr] = struct{}{}
}
if strings.Contains(publisherAddr, "ws") && !strings.Contains(publisherAddr, "https") {
uniqueWSAddrs[publisherAddr] = struct{}{}
}
if strings.Contains(publisherAddr, "https") || strings.Contains(publisherAddr, "wss") {
for _, providerAddr := range entry.AddrInfo.Addrs {
addrPair := fmt.Sprintf("%s : %s", publisherAddr, providerAddr)
uniqueHTTPSAddrs[addrPair] = struct{}{}
}
}
}
}
if entry.FrozenAt != nil {
frozenCount++
}
adTime, err := time.Parse(time.RFC3339, entry.LastAdvertisementTime)
if err == nil && adTime.After(sixMonthsAgo) {
adsWithin6Months++
}
}
// Printing results
fmt.Println("Number of unique publisher Addrs:", len(uniqueAddrs))
fmt.Println("Number of unique TCP publisher Addrs:", len(uniqueTCPAddrs))
fmt.Println("Number of unique WS publisher Addrs:", len(uniqueWSAddrs))
fmt.Println("Number of unique HTTPS publisher Addrs:", len(uniqueHTTPSAddrs))
fmt.Println("HTTPS publisher addresses and their provider addresses:")
for addrPair := range uniqueHTTPSAddrs {
fmt.Printf("\t%s\n", addrPair)
}
fmt.Println("Number of unique publisher IDs:", len(uniquePublisherIDs))
fmt.Println("Number of FrozenAt entries:", frozenCount)
fmt.Println("Number of advertisements within the last 6 months:", adsWithin6Months)
}