Created
August 1, 2020 21:37
-
-
Save spacelatte/f6dd2e1dcb5f615ec631fbb8405ebf6e to your computer and use it in GitHub Desktop.
cloudflare ddns dynamic dns script (from: https://notryan.com/code/net/cloudflare-ddns.js)
This file contains hidden or 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
#!/usr/bin/env node | |
const EMAIL = "[email protected]"; | |
const X_AUTH_KEY = "ABCDE"; | |
const ZONE = "ABCDE"; | |
const os = require("os"); | |
const fetch = require("node-fetch"); | |
const cf = require("cloudflare")({ | |
email: EMAIL, | |
key: X_AUTH_KEY | |
}); | |
(async function() { | |
const record_name = `${os.hostname}.example.com`; | |
const response = await fetch("http://ifconfig.co/ip"); | |
const ip = (await response.text()).trim(); | |
const records = (await cf.dnsRecords.browse(ZONE)).result; | |
const id = (function() { | |
for (let record of records) { | |
if (record.name == record_name) | |
return record.id; | |
} | |
})(); | |
if (id === undefined) { | |
console.log(await cf.dnsRecords.add(ZONE, { | |
type: "A", | |
name: record_name, | |
content: ip | |
})); | |
} else { | |
console.log(await cf.dnsRecords.edit(ZONE, id, { | |
type: "A", | |
name: record_name, | |
content: ip | |
})); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment