Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix JSON file output #183

Merged
merged 15 commits into from
Jan 21, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.dylib
*.idea
.vscode
.devcontainer

# Test binary, built with `go test -c`
*.test
Expand Down
14 changes: 10 additions & 4 deletions examples/simple.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"encoding/json"
"log"

asnmap "github.com/projectdiscovery/asnmap/libs"
Expand Down Expand Up @@ -37,15 +37,21 @@ func main() {
}

func handleInput(client *asnmap.Client, item string) {
results, err := client.GetData(item)
responses, err := client.GetData(item)
if err != nil {
log.Fatal(err)
}
output, err := asnmap.GetFormattedDataInJson(results)
results, err := asnmap.MapToResults(responses)
if err != nil {
log.Fatal(err)
}

output, err := json.Marshal(results)
if err != nil {
log.Fatal(err)
}

if len(output) > 0 {
log.Println(fmt.Sprintf("%s: %s", item, string(output)))
log.Printf("%s: %s", item, string(output))
}
}
11 changes: 6 additions & 5 deletions libs/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestGetASNFromIP(t *testing.T) {
ip string
result []*Response
}{
{"found", "100.19.12.21", []*Response{{FirstIp: "", LastIp: "", Input: "100.19.12.21", ASN: 701, Country: "US", Org: "UUNET"}}},
{"found", "100.19.12.21", []*Response{{FirstIp: "", LastIp: "", Input: "100.19.12.21", ASN: 701, Country: "US", Org: "uunet"}}},
{"not found", "255.100.100.100", []*Response{}},
}

Expand Down Expand Up @@ -51,7 +51,7 @@ func TestGetIPFromASN(t *testing.T) {
Input: "14421",
ASN: 14421,
Country: "US",
Org: "THERAVANCE",
Org: "theravance",
}},
},
{
Expand All @@ -62,23 +62,23 @@ func TestGetIPFromASN(t *testing.T) {
Input: "7712",
ASN: 7712,
Country: "KH",
Org: "SABAY Sabay Digital Cambodia",
Org: "sabay sabay digital cambodia",
},
{
FirstIp: "118.67.203.0",
LastIp: "118.67.207.255",
Input: "7712",
ASN: 7712,
Country: "KH",
Org: "SABAY Sabay Digital Cambodia",
Org: "sabay sabay digital cambodia",
},
{
FirstIp: "2405:aa00::",
LastIp: "2405:aa00:ffff:ffff:ffff:ffff:ffff:ffff",
Input: "7712",
ASN: 7712,
Country: "KH",
Org: "SABAY Sabay Digital Cambodia",
Org: "sabay sabay digital cambodia",
}},
},
}
Expand All @@ -96,6 +96,7 @@ func TestGetIPFromASN(t *testing.T) {
}

func TestGetASNFromOrg(t *testing.T) {
t.Skip("asnmap-server returns null for this query, skipping")
client, err := NewClient()
require.Nil(t, err)

Expand Down
107 changes: 0 additions & 107 deletions libs/formatter.go

This file was deleted.

128 changes: 0 additions & 128 deletions libs/formatter_test.go

This file was deleted.

Loading