Create Your Own Telegram Bot to Track IPv4 Blacklists
Creating a simple bot to automate processes on your server using services from AlexHost is easier than it seems. Following the step-by-step instructions, you will be able to set up a bot that will perform tasks without your intervention. We offer accessible and understandable tools that make the entire process simple and fast, even if you do not have deep technical knowledge. Our clients often note that with step-by-step guidance and support from the AlexHost team, bot development becomes an exciting and hassle-free process. Try it yourself – and see that creating a bot for your task is not as difficult as it may seem at first glance!
Preparing to create a bot
Before you actually start working with installing the bot on your server, you need to addhttps://dev.alexhost.com/faq/create-your-own-telegram-bot-to-track-ipv4-blacklists/?preview=trueitionally install the necessary libraries. To do this, make sure you have Python installed (version 3.7 or higher is recommended). Then install the necessary libraries using pip:
pip install selenium
pip install aiogram==3.4.1
Creating a Bot in Telegram
Step #1. In your Telegram App, find the BotFather bot. BotFather is an official Telegram bot used to create and manage other bots. With it, you can register new bots, configure their parameters, get API tokens, and update information such as a description, avatar, or commands. This is the first step to launching your own Telegram bot.
Step #2. Then you need to create a new bot with the /newbot command and follow the further instructions.
Step #3. After all the steps have been done correctly, you need to copy the token of your bot, it will be needed in the code. You will receive a message like this: Done! Congratulations on your new bot. You will find it at your_new-bot_name.
Step #4. Next we proceed to the difficult and important step of writing the code. On your server you need to create a file, for example my_bot.py, and insert the following code (this code is aimed at creating a bot to check IPv4 addresses for blacklists):
import asyncio
from aiogram import Bot, Dispatcher, F
from aiogram.types import Message
from aiogram.filters import CommandStart
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
bot = Bot('YOUR_BOT_TOKEN_HERE') # Replace with your bot's token
dp = Dispatcher()
def get_results(IP):
results = []
driver = webdriver.Chrome()
driver.get("https://mxtoolbox.com/SuperTool.aspx?action=blacklist%3a81.200.16.134&run=toolpage") # the URL, where you can check directly the blacklist status
time.sleep(5) # wait for page to load
input_field = driver.find_element(By.NAME, 'ctl00$ContentPlaceHolder1$txtInput2')
input_field.clear()
input_field.send_keys(IP)
time.sleep(4)
search_button = driver.find_element(By.ID, 'btnAction3')
search_button.click()
time.sleep(5)
status_results = driver.find_elements(By.CLASS_NAME, 'table-column-Status')[:60]
name_results = driver.find_elements(By.CLASS_NAME, 'table-column-Name')[:60]
if len(status_results) == len(name_results):
for status, name in zip(status_results, name_results):
results.append([status.text, name.text])
else:
print("The number of statuses and names does not match!")
driver.quit()
return results
@dp.message(CommandStart())
async def start(message: Message):
await message.answer(f'Привет {message.from_user.first_name}, Enter your IP to check')
@dp.message(F.text)
async def get_IP(message: Message):
text = ''
await message.answer('Checking the IPv4')
for results in get_results(message.text):
if status.strip() == 'OK':
text += f'✅: {name}\n'
else:
text += f'❌: {name}\n'
await message.answer(text)
async def main():
await dp.start_polling(bot)
if __name__ == '__main__':
print("Bot is running")
asyncio.run(main())
Here is a practical example of a Telegram bot you can start using right now, by clicking here! This bot is the result of the code outlined earlier in this article, designed to help you efficiently check whether your IPv4 address is listed in spam databases. By using this bot, you can ensure your IP maintains its integrity and stays free from blacklisting issues. Test it out today and experience the convenience of automated monitoring!
Regularly checking your IPv4 address against spam databases is essential for maintaining the reliability and reputation of your services. An IP listed on blacklists can lead to blocked email delivery, diminished customer trust, and technical disruptions. At AlexHost, we enforce a strict no-spam policy to safeguard our network and clients. Any activities that might result in IP blacklisting (such as those flagged by SpamHaus, StopForumSpam, SpamCop, Blocklist, or similar databases) are prohibited, and such services are promptly suspended to maintain network integrity.