Skip to content

Instantly share code, notes, and snippets.

@MParvin
Created October 12, 2024 20:58
Show Gist options
  • Save MParvin/baebb0116939fa01f1248493f5473f0d to your computer and use it in GitHub Desktop.
Save MParvin/baebb0116939fa01f1248493f5473f0d to your computer and use it in GitHub Desktop.
Effortlessly monitor the availability of .ir domains and receive instant notifications when they become free—no external dependencies required.
#!/usr/bin/env python
import sys
import requests
import os
def read_config():
with open(".env", "r") as f:
config = {}
for line in f:
key, value = line.strip().split("=")
config[key] = value
return config
def send_telegram(message, telegram_token, chat_id):
url = "https://api.telegram.org/bot{}/sendMessage".format(telegram_token)
data = {
"chat_id": chat_id,
"text": message
}
response = requests.post(url, data=data)
if response.status_code == 200:
print("Message sent successfully")
else:
print("Error: Unable to send message")
def is_domain_free(domain):
url = f"https://whois.nic.ir/Query_Whois_Server?name={domain}"
response = requests.get(url)
if response.status_code == 200:
if "no entries found" in response.text:
return True
else:
return False
else:
print("Error: Unable to check domain availability")
return False
def main():
if len(sys.argv) != 2:
print("Usage: python ir-domains-telegram.py <domain>.ir")
sys.exit(1)
if not sys.argv[1].endswith(".ir"):
print("Please enter a valid .ir domain")
sys.exit(1)
if not os.path.exists(".env"):
print("Please create a .env file with TELEGRAM_TOKEN and TELEGRAM_CHAT_ID")
sys.exit(1)
config = read_config()
if config["TELEGRAM_TOKEN"] is None or config["TELEGRAM_CHAT_ID"] is None:
print("Please set TELEGRAM_TOKEN and TELEGRAM_CHAT_ID in .env file")
sys.exit(1)
domain = sys.argv[1]
print(domain)
if is_domain_free(domain):
message = f"{domain} is available"
print(message)
send_telegram(message, config["TELEGRAM_TOKEN"], config["TELEGRAM_CHAT_ID"])
else:
print(f"{domain} is not available")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment