- Support for single record deployment - Batch deployment from JSON config - Service quick deployment (Web/API/CDN) - .env file support for secure credentials - Complete documentation
69 lines
1.6 KiB
Python
Executable File
69 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
DNS记录删除脚本
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
from deploy_record import (
|
|
call_api,
|
|
find_record,
|
|
load_env
|
|
)
|
|
|
|
# 加载 .env
|
|
load_env()
|
|
|
|
def delete_record(domain, subdomain, record_type):
|
|
"""删除DNS记录"""
|
|
print(f"\n删除DNS记录: {subdomain or '@'}.{domain} ({record_type})")
|
|
|
|
# 查找记录
|
|
record = find_record(domain, subdomain, record_type)
|
|
|
|
if not record:
|
|
print(f"✗ 记录不存在")
|
|
return False
|
|
|
|
record_id = record.get("RecordId")
|
|
current_value = record.get("Value")
|
|
|
|
print(f" 记录ID: {record_id}")
|
|
print(f" 当前值: {current_value}")
|
|
|
|
# 确认删除
|
|
response = input("\n确认删除? (y/N): ")
|
|
if response.lower() != 'y':
|
|
print(" 已取消")
|
|
return False
|
|
|
|
# 调用删除API
|
|
try:
|
|
params = {
|
|
"Domain": domain,
|
|
"RecordId": record_id
|
|
}
|
|
result = call_api("DeleteRecord", params)
|
|
print(f"✓ 记录删除成功")
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ 记录删除失败: {e}")
|
|
return False
|
|
|
|
def main():
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(description='删除DNS记录')
|
|
|
|
parser.add_argument('--domain', required=True, help='域名(如: example.com)')
|
|
parser.add_argument('--subdomain', default='@', help='子域名(默认: @)')
|
|
parser.add_argument('--type', required=True, help='记录类型(A/CNAME/MX等)')
|
|
|
|
args = parser.parse_args()
|
|
|
|
success = delete_record(args.domain, args.subdomain, args.type)
|
|
sys.exit(0 if success else 1)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|