Features: - Domain management (check, register, renew, contacts) - DNS management (nameservers, records) - Glue records (child nameserver) support - TLD price tracking with KRW conversion - FastAPI REST server with OpenAI schema - MCP server for Claude integration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
"""
|
|
Namecheap API 사용 예제
|
|
"""
|
|
|
|
import os
|
|
from dotenv import load_dotenv
|
|
from namecheap import NamecheapAPI, NamecheapConfig, NamecheapError
|
|
|
|
load_dotenv()
|
|
|
|
# 설정
|
|
config = NamecheapConfig(
|
|
api_user=os.getenv("NAMECHEAP_API_USER", ""),
|
|
api_key=os.getenv("NAMECHEAP_API_KEY", ""),
|
|
username=os.getenv("NAMECHEAP_USERNAME", ""),
|
|
client_ip=os.getenv("NAMECHEAP_CLIENT_IP", ""),
|
|
sandbox=os.getenv("NAMECHEAP_SANDBOX", "true").lower() == "true",
|
|
)
|
|
|
|
api = NamecheapAPI(config)
|
|
|
|
# === 도메인 가용성 확인 ===
|
|
try:
|
|
result = api.domains_check(["example.com", "example.net", "example.org"])
|
|
for domain, available in result.items():
|
|
status = "사용 가능" if available else "이미 등록됨"
|
|
print(f"{domain}: {status}")
|
|
except NamecheapError as e:
|
|
print(f"Error: {e}")
|
|
|
|
# === 내 도메인 목록 조회 ===
|
|
try:
|
|
domains = api.domains_get_list()
|
|
for d in domains:
|
|
print(f"{d['name']} - 만료일: {d['expires']}")
|
|
except NamecheapError as e:
|
|
print(f"Error: {e}")
|
|
|
|
# === DNS 레코드 조회 ===
|
|
try:
|
|
records = api.dns_get_hosts("example", "com")
|
|
for r in records:
|
|
print(f"{r['name']}.example.com -> {r['type']} -> {r['address']}")
|
|
except NamecheapError as e:
|
|
print(f"Error: {e}")
|
|
|
|
# === DNS 레코드 설정 ===
|
|
try:
|
|
new_records = [
|
|
{"name": "@", "type": "A", "address": "1.2.3.4", "ttl": "1800"},
|
|
{"name": "www", "type": "CNAME", "address": "example.com", "ttl": "1800"},
|
|
{"name": "@", "type": "MX", "address": "mail.example.com", "mx_pref": "10"},
|
|
]
|
|
success = api.dns_set_hosts("example", "com", new_records)
|
|
print(f"DNS 설정 {'성공' if success else '실패'}")
|
|
except NamecheapError as e:
|
|
print(f"Error: {e}")
|
|
|
|
# === 계정 잔액 조회 ===
|
|
try:
|
|
balance = api.users_get_balances()
|
|
print(f"잔액: ${balance['available_balance']:.2f} {balance['currency']}")
|
|
except NamecheapError as e:
|
|
print(f"Error: {e}")
|