initial
This commit is contained in:
91
main.go
Executable file
91
main.go
Executable file
@@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
xj "github.com/basgys/goxml2json"
|
||||
)
|
||||
|
||||
/*
|
||||
#! /bin/bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
rawraw="$( \
|
||||
curl "https://www.namesilo.com/api/dnsListRecords?version=1&type=xml&key=7a26bd4b7aedbc6c44f56af38&domain=blapointe.com" 2> /dev/null \
|
||||
| xq .namesilo \
|
||||
)"
|
||||
echo $rawraw | jq . >&2
|
||||
ip="$( \
|
||||
echo "$rawraw" \
|
||||
| jq -r .request.ip \
|
||||
)"
|
||||
echo ip $ip >&2
|
||||
raw="$( \
|
||||
echo "$rawraw" \
|
||||
| jq -c '.reply.resource_record[]' \
|
||||
| grep \*.home.blapointe \
|
||||
| jq -c . \
|
||||
| jq -c . \
|
||||
)"
|
||||
echo raw $raw >&2
|
||||
rid="$( \
|
||||
echo "$raw" \
|
||||
| jq -r .record_id \
|
||||
)"
|
||||
ip="$(curl icanhazip.com 2> /dev/null)"
|
||||
echo $rid
|
||||
echo curl "https://www.namesilo.com/api/dnsUpdateRecord?version=1&type=xml&key=7a26bd4b7aedbc6c44f56af38&domain=blapointe.com&rrid=$rid&rrhost=*.home&rrvalue=$ip&rrttl=7207"
|
||||
curl "https://www.namesilo.com/api/dnsUpdateRecord?version=1&type=xml&key=7a26bd4b7aedbc6c44f56af38&domain=blapointe.com&rrid=$rid&rrhost=*.home&rrvalue=$ip&rrttl=7207" 2> /dev/null \
|
||||
| xq .
|
||||
*/
|
||||
|
||||
func main() {
|
||||
resp, err := http.Get("https://www.namesilo.com/api/dnsListRecords?version=1&type=xml&key=7a26bd4b7aedbc6c44f56af38&domain=blapointe.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
buff := bytes.NewBuffer(b)
|
||||
js, err := xj.Convert(buff)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var rawraw struct {
|
||||
Namesilo struct {
|
||||
Request struct {
|
||||
IP string `json:"ip"`
|
||||
} `json:"request"`
|
||||
Reply struct {
|
||||
ResourceRecord []struct {
|
||||
Host string `json:"host"`
|
||||
RecordID string `json:"record_id"`
|
||||
} `json:"resource_record"`
|
||||
} `json:"reply"`
|
||||
} `json:"namesilo"`
|
||||
}
|
||||
if err := json.NewDecoder(strings.NewReader(js.String())).Decode(&rawraw); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, v := range rawraw.Namesilo.Reply.ResourceRecord {
|
||||
if v.Host == "*.home.blapointe.com" {
|
||||
rrid := v.RecordID
|
||||
ip := rawraw.Namesilo.Request.IP
|
||||
log.Println(rrid, ip)
|
||||
url := fmt.Sprintf("https://www.namesilo.com/api/dnsUpdateRecord?version=1&type=xml&key=7a26bd4b7aedbc6c44f56af38&domain=blapointe.com&rrid=%s&rrhost=*.home&rrvalue=%s&rrttl=3600", rrid, ip)
|
||||
resp, err := http.Get(url)
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
js, _ := xj.Convert(bytes.NewBuffer(b))
|
||||
log.Printf("%v: %s", err, js)
|
||||
return
|
||||
}
|
||||
}
|
||||
log.Println(rawraw)
|
||||
}
|
||||
Reference in New Issue
Block a user