Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.