Skip to content

Instantly share code, notes, and snippets.

@vrajroham
Last active February 16, 2025 19:46
Show Gist options
  • Save vrajroham/dbbb482ad5e7f999d26dcd3d301ee1bc to your computer and use it in GitHub Desktop.
Save vrajroham/dbbb482ad5e7f999d26dcd3d301ee1bc to your computer and use it in GitHub Desktop.
Domain Availability Checker

Repo Structure

your-repo/
├── .github/
│   └── workflows/
│       └── check_domains.yml
├── README.md
└── domain_availability.py

Steps

  • Add secret DOMAINS and value must be comma seperated domains e.g. "google.com,youtube.com"
  • Add scret SLACK_WEBHOOK_URL, must be incoming webhook url
  • Update the SLACK_CHANNEL_NAME in domain_availability.py to your slack channel name

Updates

  • Change the cron schedule according to your need
name: Check Domain Expiry
on:
schedule:
- cron: "30 2 * * *" # Runs at 2:30 AM UTC (8:00 AM IST)
workflow_dispatch: # Allows manual trigger
jobs:
check-domains:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: pip install requests
- name: Debug Environment
run: |
echo "Checking if secrets are set (will not show values):"
if [ -n "$DOMAINS" ]; then echo "DOMAINS is set"; else echo "DOMAINS is not set"; fi
if [ -n "$SLACK_WEBHOOK_URL" ]; then echo "SLACK_WEBHOOK_URL is set"; else echo "SLACK_WEBHOOK_URL is not set"; fi
env:
DOMAINS: ${{ secrets.DOMAINS }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Run domain check script
env:
DOMAINS: ${{ secrets.DOMAINS }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: python domain_availability.py
import os
import requests
import json
from datetime import datetime, timedelta
# Get domains from environment variable
DOMAINS = os.getenv("DOMAINS", "")
if not DOMAINS:
print("No domains provided. Exiting.")
exit(1)
DOMAINS = [domain.strip() for domain in DOMAINS.split(",")]
# Slack Webhook URL (Set this as a GitHub Secret)
SLACK_WEBHOOK_URL = os.getenv("SLACK_WEBHOOK_URL")
SLACK_CHANNEL_NAME = "#domain-checks" # Make sure to add your channel name, else slack API will fail
def send_notification(message, channel="slack"):
"""Send a notification to the desired channel (Slack, Telegram, etc.)."""
if channel == "slack":
send_slack_message(message)
else:
print(f"Unknown channel: {channel}")
def send_slack_message(message):
"""Send a message to Slack."""
if not SLACK_WEBHOOK_URL:
print("Slack Webhook URL not configured.")
return
payload = {
"text": message,
"channel": SLACK_CHANNEL_NAME,
"icon_emoji": ":squirrel:",
"username": "Domain Spy"
}
headers = {"Content-Type": "application/json"}
response = requests.post(SLACK_WEBHOOK_URL, data=json.dumps(payload), headers=headers)
if response.status_code == 200:
print("Slack message sent successfully.")
else:
print(f"Failed to send Slack message: {response.text}")
def check_domain(domain):
"""Check domain status via WHOIS API."""
url = f"http://api.whois.vu/?q={domain}"
try:
response = requests.get(url)
data = response.json()
print(f"Domain {domain} available? {data['available']}")
# Check if domain is available
if data['available'] == "yes":
send_notification(f"🎯 The domain `{domain}` is available for registration! Act fast!")
if "expires" in data:
expiry_date = datetime.utcfromtimestamp(data["expires"])
today = datetime.utcnow()
print(f"Domain {domain} expires on {expiry_date.date()}")
# Check if the domain is expiring in 30 days
if expiry_date == today + timedelta(days=30):
send_notification(f"⚠️ The domain `{domain}` will expire in 30 days on {expiry_date.date()}. Be ready to grab it!")
elif expiry_date < today:
send_notification(f"❌ The domain `{domain}` has expired on {expiry_date.date()}. Check if it's available for purchase!")
# Check if the domain is pending delete
if "statuses" in data and "pendingDelete" in data["statuses"]:
send_notification(f"🚨 The domain `{domain}` is pending deletion! Stay alert!")
except Exception as e:
print(f"Error checking domain {domain}: {e}")
# Check all domains
for domain in DOMAINS:
check_domain(domain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment