/
as_write.go
126 lines (116 loc) · 3.57 KB
/
as_write.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
package db
import (
"fmt"
"strconv"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
func AsnDetailsMongo(
ad AsnDetails, apr AsnPrefixes, ape AsnPeers, wd WhoisDetails,
) error {
client, ctx := DB.Client, DB.Ctx
// defer func() {
// if err := client.Disconnect(ctx); err != nil {
// panic(err)
// }
// }()
collection := client.Database("masscan_go").Collection("as")
opts := options.Update().SetUpsert(true)
fmt.Println("ASN IS: " + strconv.Itoa(ad.Data.Asn))
res, err := collection.UpdateOne(ctx,
bson.M{"as_number": strconv.Itoa(ad.Data.Asn)},
bson.M{"$set": bson.M{
"description_short": ad.Data.DescriptionShort,
"description_full": ad.Data.DescriptionFull,
"peers": ape.Data.Ipv4Peers,
"ipV6peers": ape.Data.Ipv6Peers,
"prefixes": apr.Data.Ipv4Prefixes,
"ipV6prefixes": apr.Data.Ipv6Prefixes,
"organisation": bson.M{
"address": wd.Organisation["address"],
"org-name": wd.Organisation["org-name"],
"phone": wd.Organisation["phone"],
"fax-no": wd.Organisation["fax-no"],
"organisation": wd.Organisation["organisation"],
},
"autnum": bson.M{
"created": wd.Autnum["created"],
"last-modified": wd.Autnum["last-modified"],
"remarks": wd.Autnum["remarks"],
},
"persons": wd.Persons}},
opts)
if err != nil {
return err
}
fmt.Println(res)
fmt.Println(err)
return nil
}
type AsnDetails struct {
Status string `json:"status"`
StatusMessage string `json:"status_message"`
Data struct {
Asn int `json:"asn"`
Name interface{} `json:"name"`
DescriptionShort string `json:"description_short"`
DescriptionFull []string `json:"description_full"`
CountryCode string `json:"country_code"`
Website interface{} `json:"website"`
} `json:"data"`
}
type AsnPeers struct {
Status string `json:"status"`
StatusMessage string `json:"status_message"`
Data struct {
Ipv4Peers []struct {
Asn int `json:"asn"`
Name interface{} `json:"name"` // seems to be always null
Description string `json:"description"`
CountryCode string `json:"country_code"`
} `json:"ipv4_peers"`
Ipv6Peers []struct {
Asn int `json:"asn"`
Name interface{} `json:"name"`
Description string `json:"description"`
CountryCode string `json:"country_code"`
} `json:"ipv6_peers"`
} `json:"data"`
}
type AsnPrefixes struct {
Status string `json:"status"`
StatusMessage string `json:"status_message"`
Data struct {
Ipv4Prefixes []struct {
// Prefix string `json:"prefix"`
IP string `json:"ip"`
Cidr int `json:"cidr"`
Name string `json:"name"`
Description string `json:"description"`
CountryCode string `json:"country_code"`
Parent struct {
Prefix string `json:"prefix"`
IP string `json:"ip"`
Cidr int `json:"cidr"`
} `json:"parent"`
} `json:"ipv4_prefixes"`
Ipv6Prefixes []struct {
// Prefix string `json:"prefix"`
IP string `json:"ip"`
Cidr int `json:"cidr"`
Name string `json:"name"`
Description string `json:"description"`
CountryCode string `json:"country_code"`
Parent struct {
Prefix string `json:"prefix"`
IP string `json:"ip"`
Cidr int `json:"cidr"`
} `json:"parent"`
} `json:"ipv6_prefixes"`
} `json:"data"`
}
type WhoisDetails struct {
Organisation map[string]string
Autnum map[string]string
Persons []map[string]string
}