Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Forked from kenjiskywalker/pit.yaml
Last active December 25, 2015 08:59
Show Gist options
  • Save hnakamur/6950596 to your computer and use it in GitHub Desktop.
Save hnakamur/6950596 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/typester/go-pit"
"io/ioutil"
"log"
"net"
"net/http"
)
type Record struct {
Ip string
Domain string
}
func GetPitData(data string) (string, string, error) {
vd, err := pit.Get(data, pit.Requires{})
if err != nil {
return "", "", err
}
domain := (*vd)["domain"]
if domain == "" {
log.Fatalln("no such domain")
}
password := (*vd)["password"]
if password == "" {
log.Fatalln("no such password")
}
return domain, password, nil
}
func GetCurrentIP() (string, error) {
response, err := http.Get("http://temple-kun.appspot.com/")
if err != nil {
return "", err
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
return string(contents), nil
}
func GetDomainIP(domain string, subDomains []string) ([]Record, error) {
records := make([]Record, len(subDomains))
s := ""
for i, subDomain := range subDomains {
s = subDomain + "." + domain
v, err := net.LookupHost(s)
if err != nil {
return nil, err
}
records[i] = Record{s, v[0]}
}
return records, nil
}
func main() {
pitDomain := "value-domain"
subDomains := []string{"www", "www2", "www3"}
domain, password, err := GetPitData(pitDomain)
if err != nil {
log.Fatal(err)
}
currentIpAddr, err := GetCurrentIP()
if err != nil {
log.Fatal(err)
}
records, err := GetDomainIP(domain, subDomains)
if err != nil {
log.Fatal(err)
}
for i := range subDomains {
record := records[i]
fmt.Printf("domain : %s\ndomain IP : %s\ncurrent IP : %s\n",
record.Domain,
record.Ip,
currentIpAddr,
)
if record.Domain == currentIpAddr {
fmt.Println("STATUS : same\n")
continue
}
fmt.Println("STATUS : not equal")
url := fmt.Sprintf("http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=%s&p=%s&h=%s&i=%s",
domain,
password,
subDomains[i],
currentIpAddr,
)
fmt.Println(url)
response, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
log.Println(string(contents))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment