mirror of
https://github.com/tiennm99/MTTools.git
synced 2026-10-14 18:19:03 +00:00
Update main.sh
This commit is contained in:
1 parent
a25de1de5b
commit
befceed53e
1 file changed
+6
-6
+6
-6
@@ -7,7 +7,7 @@ RECORDS=("subdomain1.example.com" "subdomain2.example.com" "subdomain3.example.c
|
|||||||
|
|
||||||
# Get current IP address using upnpc
|
# Get current IP address using upnpc
|
||||||
CURRENT_IP=$(upnpc -s | awk -F'= ' '/ExternalIPAddress/ { print $2 }')
|
CURRENT_IP=$(upnpc -s | awk -F'= ' '/ExternalIPAddress/ { print $2 }')
|
||||||
echo "Current IP: $CURRENT_IP\n"
|
echo "Current IP: $CURRENT_IP"
|
||||||
|
|
||||||
# Function to update DNS record
|
# Function to update DNS record
|
||||||
update_record() {
|
update_record() {
|
||||||
@@ -18,22 +18,22 @@ update_record() {
|
|||||||
--header "Authorization: Bearer $API_KEY" \
|
--header "Authorization: Bearer $API_KEY" \
|
||||||
| jq -r '.result[0].id')
|
| jq -r '.result[0].id')
|
||||||
|
|
||||||
if [ -n "$record_id" ]; then
|
if [ "$record_id" != "null" ] && [ -n "$record_id" ]; then
|
||||||
echo "Found existing record $record with ID $record_id\n"
|
echo "Found existing record $record with ID $record_id"
|
||||||
curl --request PUT \
|
curl --request PUT \
|
||||||
--url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$record_id \
|
--url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$record_id \
|
||||||
--header "Content-Type: application/json" \
|
--header "Content-Type: application/json" \
|
||||||
--header "Authorization: Bearer $API_KEY" \
|
--header "Authorization: Bearer $API_KEY" \
|
||||||
--data "{\"content\":\"$CURRENT_IP\",\"name\":\"$record\",\"proxied\":false,\"type\":\"A\",\"ttl\":3600}"
|
--data "{\"content\":\"$CURRENT_IP\",\"name\":\"$record\",\"proxied\":false,\"type\":\"A\",\"ttl\":3600}"
|
||||||
echo "Updated $record to $CURRENT_IP\n"
|
echo "Updated $record to $CURRENT_IP"
|
||||||
else
|
else
|
||||||
echo "No A record found for $record, creating a new one\n"
|
echo "No A record found for $record, creating a new one"
|
||||||
curl --request POST \
|
curl --request POST \
|
||||||
--url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records \
|
--url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records \
|
||||||
--header "Content-Type: application/json" \
|
--header "Content-Type: application/json" \
|
||||||
--header "Authorization: Bearer $API_KEY" \
|
--header "Authorization: Bearer $API_KEY" \
|
||||||
--data "{\"content\":\"$CURRENT_IP\",\"name\":\"$record\",\"proxied\":false,\"type\":\"A\",\"ttl\":3600}"
|
--data "{\"content\":\"$CURRENT_IP\",\"name\":\"$record\",\"proxied\":false,\"type\":\"A\",\"ttl\":3600}"
|
||||||
echo "Created A record for $record with IP $CURRENT_IP\n"
|
echo "Created A record for $record with IP $CURRENT_IP"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user