Last active
December 25, 2015 03:59
-
-
Save kenjiskywalker/6914101 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"value-domain": | |
"domain" : DOMAIN | |
"password" : PASSWORD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/typester/go-pit" | |
"io/ioutil" | |
"log" | |
"net" | |
"net/http" | |
) | |
type PitSetting struct { | |
Domain string | |
Password string | |
} | |
type Record struct { | |
Domain string | |
Ip string | |
} | |
func GetPitData(data string) (*PitSetting, error) { | |
vd, err := pit.Get(data, pit.Requires{}) | |
if err != nil { | |
return nil, err | |
} | |
p := new(PitSetting) | |
p.Domain = (*vd)["domain"] | |
if p.Domain == "" { | |
log.Fatalln("no such domain") | |
} | |
p.Password = (*vd)["password"] | |
if p.Password == "" { | |
log.Fatalln("no such password") | |
} | |
return p, 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, 0, len(subDomains)) | |
for _, subDomain := range subDomains { | |
s := subDomain + "." + domain | |
v, err := net.LookupHost(s) | |
if err != nil { | |
return nil, err | |
} | |
records = append(records, Record{s, v[0]}) | |
} | |
return records, nil | |
} | |
func main() { | |
pitDomain := "value-domain" | |
subDomains := []string{"www", "www2", "www3"} | |
pit, err := GetPitData(pitDomain) | |
if err != nil { | |
log.Fatal(err) | |
} | |
currentIpAddr, err := GetCurrentIP() | |
if err != nil { | |
log.Fatal(err) | |
} | |
records, err := GetDomainIP(pit.Domain, subDomains) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for i := range subDomains { | |
fmt.Printf("domain : %s\ndomain IP : %s\ncurrent IP : %s\n", | |
records[i].Domain, | |
records[i].Ip, | |
currentIpAddr, | |
) | |
if records[i].Ip == currentIpAddr { | |
fmt.Println("STATUS : same\n") | |
continue | |
} else { | |
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", | |
pit.Domain, | |
pit.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