Attempting to create a for loop for each part of a map.
map[
asn:AS10
time:1.428790768e+09
ipv4s:[
68.114.75.0/24
216.215.56.0/22
216.215.60.0/22]
ipv6s:[
2607:f3f8::/32
]]
The above is the map, I'd like to try create a for loop for each value in ipv4s
.
I've attempted, but I'm clearly not doing it correctly as it's merely based off my php knowledge.:
for json_map["ipv4s"]{
//whatever
}
PHP version if anyone needs an example rather then me attempting to explain:
foreach($obj->ipv4s as $value) {
echo $value; // return an ip
}
Update
package main
import (
"fmt"
"net/http"
"os"
"encoding/json"
)
func main() {
response, err := http.Get("https://www.enjen.net/asn-blocklist/index.php?asn=" + os.Args[1] + "&type=json_split&api=1")
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
dec := json.NewDecoder(response.Body)
if dec == nil {
panic("Failed to start decoding JSON data")
}
json_map := make(map[string]interface{})
err = dec.Decode(&json_map)
if err != nil {
panic(err)
}
fmt.Printf("%v
", json_map)
for i := range json_map {
for _, ip := range json_map[i]["ipv4s"] {
fmt.Printf(ip)
}
}
}
}