Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@scottdware
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottdware/43662077d7f9f6c4d220 to your computer and use it in GitHub Desktop.
Save scottdware/43662077d7f9f6c4d220 to your computer and use it in GitHub Desktop.
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