Cloudflare API Kullanarak PHP ile Tüm DNS Kayıtlarını Silme
Cloudflare ne yazık ki kendi arayüzünde toplu DNS kayıtlarını silmek için bir çözüm sunmuyor.
Ancak PHP ile küçük bir kodla toplu DNS kayıtlarını silebiliriz.
Api anahtarını almak için: https://dash.cloudflare.com/profile/api-tokens
İşte kodumuz:
$apiKey ="ornek"; // Cloudflare API anahtarınızı buraya ekleyin$email ="ornek@ornek.com"; // Cloudflare hesap e-posta adresiniz$domain ="ornek.com"; // DNS kayıtlarını silmek istediğiniz alan adı// Cloudflare API URL'si$apiUrl ="https://api.cloudflare.com/client/v4/zones";// Zoneleri çek$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "{$apiUrl}?name={$domain}");curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_HTTPHEADER, array( "X-Auth-Email: {$email}", "X-Auth-Key: {$apiKey}", "Content-Type: application/json"));$response = curl_exec($ch);curl_close($ch);$zoneData = json_decode($response, true);if (isset($zoneData['success']) && $zoneData['success'] && isset($zoneData['result']) && count($zoneData['result']) > 0) { $zoneId = $zoneData['result'][0]['id']; // Zonun tüm DNS kayıtlarını çek $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "{$apiUrl}/{$zoneId}/dns_records"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "X-Auth-Email: {$email}", "X-Auth-Key: {$apiKey}", "Content-Type: application/json" )); $response = curl_exec($ch); curl_close($ch); $dnsRecords = json_decode($response, true); if (isset($dnsRecords['success']) && $dnsRecords['success'] && isset($dnsRecords['result']) && count($dnsRecords['result']) > 0) { foreach ($dnsRecords['result'] as $record) { // Her bir DNS kaydını sil $recordId = $record['id']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "{$apiUrl}/{$zoneId}/dns_records/{$recordId}"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "X-Auth-Email: {$email}", "X-Auth-Key: {$apiKey}", "Content-Type: application/json" )); $response = curl_exec($ch); curl_close($ch); echo "DNS Record '{$record['name']}' deleted.\n"; } } else { echo "No DNS records found for the zone.\n"; }} else { echo "Zone not found.\n";}
Bu yazı çok hoşuma gitti, yazarın samimiyeti ve anlatımı beni derinden etkiledi! 👏
Bilgilendirici ve düşündürücü bir yazı, teşekkürler!