mirror of
https://github.com/tiennm99/MTTools.git
synced 2026-10-03 17:11:25 +00:00
[Add] init
This commit is contained in:
1 parent
55e7b12e91
commit
6aa89eaef7
2 files changed
+60
-1
No files matched your search
+25
-1
@@ -1 +1,25 @@
|
||||
Update CloudFlare DNS records with dynamic IP
|
||||
# update-dns
|
||||
|
||||
Update CloudFlare DNS records with dynamic IP when your IP is behind router's IP.
|
||||
|
||||
## How to use this script
|
||||
|
||||
```bash
|
||||
git clone https://github.com/tiennm99/update-dns
|
||||
cd update-dns
|
||||
nano main.sh
|
||||
# Edit value in the script
|
||||
./main.sh
|
||||
```
|
||||
|
||||
You can also use the script with cronjob to update your IP every 5 minutes
|
||||
|
||||
```bash
|
||||
crontab -e
|
||||
# Add the following line to the file
|
||||
*/5 * * * * /path/to/main.sh
|
||||
```
|
||||
|
||||
## __Note:__
|
||||
You may need to config your router to forward the ports you wanted to the exact machine.
|
||||
If you have problems, let's discuss in the discussions section.
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
CF_EMAIL="your@email.com"
|
||||
CF_API_KEY="your_cloudflare_api_key"
|
||||
ZONE_ID="your_zone_id"
|
||||
RECORDS=("subdomain1.example.com" "subdomain2.example.com" "subdomain3.example.com")
|
||||
|
||||
# Get current IP address using upnpc
|
||||
CURRENT_IP=$(upnpc -s | awk -F'= ' '/ExternalIPAddress/ { print $2 }')
|
||||
|
||||
# Function to update DNS record
|
||||
update_record() {
|
||||
local record="$1"
|
||||
local record_id=$(curl -sX GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?type=A&name=$record" \
|
||||
-H "X-Auth-Email: $CF_EMAIL" \
|
||||
-H "Authorization: Bearer $CF_API_KEY" \
|
||||
-H "Content-Type: application/json" | jq -r '.result[0].id')
|
||||
|
||||
if [ -n "$record_id" ]; then
|
||||
curl -sX PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$record_id" \
|
||||
-H "X-Auth-Email: $CF_EMAIL" \
|
||||
-H "Authorization: Bearer $CF_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data "{\"type\":\"A\",\"name\":\"$record\",\"content\":\"$CURRENT_IP\"}"
|
||||
echo "Updated $record to $CURRENT_IP"
|
||||
else
|
||||
echo "Error: $record not found"
|
||||
fi
|
||||
}
|
||||
|
||||
# Update DNS records
|
||||
for record in "${RECORDS[@]}"; do
|
||||
update_record "$record"
|
||||
done
|
||||
Reference in new issue
Block a user