-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from censoredplanet/satellitev1-analysis
#3 Satellite-v1 raw data sample analysis
- Loading branch information
Showing
14 changed files
with
899 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
all: | ||
mkdir -p bin | ||
(cd cmd; go get) | ||
(cd cmd; go vet) | ||
go build -o bin/analyze-cp cmd/analyze-cp.go | ||
go install cmd/analyze-cp.go | ||
go build -o bin/analyze-cp cmd/analyze-cp.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//Copyright 2021 Censored Planet | ||
|
||
// Package satellite contains analysis scripts for satellite data | ||
package satellite | ||
|
||
//Analyze processes data based on the type of analysis specified | ||
//Input - The data ([]map[string]interface{}), the analysisType (Specified by the user prompt) | ||
//Returns - The stats about the data (map[string]map[string]map[string]int) | ||
func Analyze(data []map[string]interface{}, analysisType string) map[string]map[string]map[string]int { | ||
var dataMap = map[string]map[string]map[string]int{} | ||
if analysisType == "Domain" { | ||
for _, result := range data { | ||
if _, ok := dataMap[result["Country"].(string)]; !ok { | ||
dataMap[result["Country"].(string)] = map[string]map[string]int{} | ||
} | ||
if _, ok := dataMap[result["Country"].(string)][result["Query"].(string)]; !ok { | ||
dataMap[result["Country"].(string)][result["Query"].(string)] = map[string]int{} | ||
} | ||
if _, ok := dataMap[result["Country"].(string)][result["Query"].(string)]["Measurements"]; !ok { | ||
dataMap[result["Country"].(string)][result["Query"].(string)]["Measurements"] = 0 | ||
} | ||
if _, ok := dataMap[result["Country"].(string)][result["Query"].(string)]["Anomalies"]; !ok { | ||
dataMap[result["Country"].(string)][result["Query"].(string)]["Anomalies"] = 0 | ||
} | ||
if result["Fetched"] == true { | ||
if _, ok := dataMap[result["Country"].(string)][result["Query"].(string)]["Confirmations"]; !ok { | ||
dataMap[result["Country"].(string)][result["Query"].(string)]["Confirmations"] = 0 | ||
} | ||
} | ||
|
||
dataMap[result["Country"].(string)][result["Query"].(string)]["Measurements"]++ | ||
|
||
if result["Anomaly"] == true { | ||
dataMap[result["Country"].(string)][result["Query"].(string)]["Anomalies"]++ | ||
} | ||
if result["Fetched"] == true { | ||
if result["Confirmed"] == "true" { | ||
dataMap[result["Country"].(string)][result["Query"].(string)]["Confirmations"]++ | ||
} | ||
} | ||
} | ||
} else if analysisType == "Vantage Point" { | ||
for _, result := range data { | ||
if _, ok := dataMap[result["Country"].(string)]; !ok { | ||
dataMap[result["Country"].(string)] = map[string]map[string]int{} | ||
} | ||
if _, ok := dataMap[result["Country"].(string)][result["Resolver"].(string)]; !ok { | ||
dataMap[result["Country"].(string)][result["Resolver"].(string)] = map[string]int{} | ||
} | ||
if _, ok := dataMap[result["Country"].(string)][result["Resolver"].(string)]["Measurements"]; !ok { | ||
dataMap[result["Country"].(string)][result["Resolver"].(string)]["Measurements"] = 0 | ||
} | ||
if _, ok := dataMap[result["Country"].(string)][result["Resolver"].(string)]["Anomalies"]; !ok { | ||
dataMap[result["Country"].(string)][result["Resolver"].(string)]["Anomalies"] = 0 | ||
} | ||
if result["Fetched"] == true { | ||
if _, ok := dataMap[result["Country"].(string)][result["Resolver"].(string)]["Confirmations"]; !ok { | ||
dataMap[result["Country"].(string)][result["Resolver"].(string)]["Confirmations"] = 0 | ||
} | ||
} | ||
|
||
dataMap[result["Country"].(string)][result["Resolver"].(string)]["Measurements"]++ | ||
|
||
if result["Anomaly"] == true { | ||
dataMap[result["Country"].(string)][result["Resolver"].(string)]["Anomalies"]++ | ||
} | ||
if result["Fetched"] == true { | ||
if result["Confirmed"] == "true" { | ||
dataMap[result["Country"].(string)][result["Resolver"].(string)]["Confirmations"]++ | ||
} | ||
} | ||
} | ||
} | ||
return dataMap | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//Copyright 2021 Censored Planet | ||
|
||
// Package satellite contains analysis scripts for satellite data | ||
package satellite | ||
|
||
import ( | ||
"encoding/csv" | ||
"fmt" | ||
"os" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
//WriteToCSV writes a map of analyzed data to a CSV file. | ||
//Input - The data to write (map[string]map[string]map[string]int), the analysis type ("Vantage Point", "Domain"), Output csv filename | ||
//Returns - None | ||
//WriteToCSV expects the data to be in a certain nested map format. | ||
func WriteToCSV(dataMap map[string]map[string]map[string]int, filename string) { | ||
file, err := os.Create(filename) | ||
if err != nil { | ||
log.Fatal("Cannot create output file: ", err.Error()) | ||
} | ||
defer file.Close() | ||
w := csv.NewWriter(file) | ||
defer w.Flush() | ||
|
||
w.Write([]string{"Country", "Vantage Point/Website", "Measurements", "Anomalies", "Confirmations"}) | ||
|
||
for country, innerMap := range dataMap { | ||
for targetValue, statsMap := range innerMap { | ||
if _, ok := statsMap["Confirmations"]; ok { | ||
err := w.Write([]string{fmt.Sprintf("%v", country), fmt.Sprintf("%v", targetValue), fmt.Sprintf("%v", statsMap["Measurements"]), fmt.Sprintf("%v", statsMap["Anomalies"]), fmt.Sprintf("%v", statsMap["Confirmations"])}) | ||
if err != nil { | ||
log.Warn("Could not write row due to: ", err.Error()) | ||
} | ||
} else { | ||
err := w.Write([]string{fmt.Sprintf("%v", country), fmt.Sprintf("%v", targetValue), fmt.Sprintf("%v", statsMap["Measurements"]), fmt.Sprintf("%v", statsMap["Anomalies"]), "N/A"}) | ||
if err != nil { | ||
log.Warn("Could not write row due to: ", err.Error()) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.