Home Projects Tutorials Contact
Back to Projects
اسکریپت تمدید خودکار IP در ویندوز

اسکریپت تمدید خودکار IP در ویندوز The automatic IP renewal script in Windows

2025/04/21

Technologies Used

Python

Project Description

در بسیاری از شبکه‌ها، به‌ویژه شبکه‌های دانشگاهی یا عمومی، سیستم‌ها به‌صورت داینامیک از طریق DHCP آدرس IP دریافت می‌کنند. این آدرس‌ها معمولاً زمان‌دار هستند و پس از مدتی منقضی می‌شوند یا توسط سرور تغییر می‌کنند. این موضوع در برخی سناریوها می‌تواند مشکلات جدی ایجاد کند.

یکی از چالش‌های رایج، از دست رفتن دسترسی به سیستم از راه دور (Remote Desktop) به دلیل تغییر IP است. به‌ویژه زمانی که کاربر بخواهد از مکان دیگری مانند منزل به سیستم دانشگاهی خود متصل شود، ندانستن IP فعلی سیستم می‌تواند اتصال را غیرممکن کند.

علاوه بر این، تغییر خودکار IP ممکن است تبعاتی مانند موارد زیر داشته باشد:

- اختلال در دسترسی به سرویس‌هایی که به IP وابسته‌اند (وب‌سرورها، دیتابیس‌ها و…)
- از کار افتادن مکانیزم‌های امنیتی مبتنی بر IP (مانند فایروال‌ها یا احراز هویت IP-based)
- امکان سوءاستفاده یا تداخل ناخواسته در شبکه‌های محلی در شرایط خاص

برای رفع این مشکل، در این پروژه یک اسکریپت پایتون طراحی شده است که به‌صورت خودکار در بازه‌های زمانی مشخص (مثلاً هر نیم‌ساعت)، اقدام به تمدید آدرس IP فعلی می‌کند. این اسکریپت اطلاعات DHCP را بررسی می‌کند، زمان اجاره IP را تشخیص می‌دهد، و درست پیش از انقضا، دستور تمدید را اجرا می‌کند. همچنین تمام رویدادها و جزئیات، مانند زمان تمدید، IP فعلی و زمان تمدید بعدی، در یک فایل متنی ثبت می‌شوند.

این راهکار ساده، کاربردی و قابل اتوماسیون است و می‌تواند به حفظ پایداری اتصال و جلوگیری از اختلال‌های ناشی از تغییر IP کمک شایانی کند.

برای مشاهده جزییات بیشتر و دیدن روش استفاده میتوانید با لینک گیت هاب پروژه به مخزن این پروژه بروید.
In many networks, especially university or public networks, systems receive IP addresses dynamically via DHCP. These addresses are usually time-limited and either expire after a while or are changed by the server. This can cause serious problems in certain scenarios.

One common challenge is losing remote access (Remote Desktop) to a system due to an IP change. Particularly when a user wants to connect to their university system from another location, such as home, not knowing the system's current IP can make the connection impossible.

Additionally, automatic IP changes can have consequences such as:

- Disruption of access to services that depend on IP addresses (web servers, databases, etc.)
- Failure of IP-based security mechanisms (such as firewalls or IP-based authentication)
- Potential for exploitation or unintended interference in local networks under specific conditions

To address this issue, a Python script has been designed in this project that automatically renews the current IP address at specified intervals (e.g., every half hour). This script checks DHCP information, detects the IP lease time, and executes the renewal command just before expiration. All events and details, such as the renewal time, current IP, and next renewal time, are recorded in a text file.

This solution is simple, practical, and automatable, and can significantly help maintain connection stability and prevent disruptions caused by IP changes.

For more details and to see how to use it, you can visit the project's GitHub repository via the project link.