Create a gist now

Instantly share code, notes, and snippets.

@scottdware /azureip_print.go Secret
Last active Aug 29, 2015

What would you like to do?
Azure IPs printed to console
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"os"
)
type AzurePublicIPAddresses struct {
Region []Region `xml:"Region"`
}
type Region struct {
Name string `xml:"Name,attr"`
Subnets []Subnet `xml:"IpRange"`
}
type Subnet struct {
Subnet string `xml:"Subnet,attr"`
}
func main() {
var azure AzurePublicIPAddresses
x, err := ioutil.ReadFile(os.Args[1])
if err != nil {
log.Fatal(err)
}
if err := xml.Unmarshal(x, &azure); err != nil {
log.Fatal(err)
}
for _, r := range azure.Region {
fmt.Printf("%+v\n", r.Name)
for _, s := range r.Subnets {
fmt.Printf("--> %+v\n", s.Subnet)
}
fmt.Print("\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment