dhcp-server-lease-script

Script ini akan bekerja ketika ada device yang pertama terhubung ke DHCP Server mikrotik dan otomatis membuat device tersebut menjadi static (Make Static).

Script ini dipasang di IP –> DHCP Server –> DHCP –> Nama DHCP Server

Share to Unlock Contentimage/svg+xml

Silahkan share untuk membuka link download dan membuka scriptnya

Apabila tutorial ini bermanfaat support saya dengan cara share artikel ini.. Terimakasih 

# Created Jotne 2019 v1.2
#
# This scripts stats all DHCP release to static automaticalle
# It should run on all routerOS version


# Test if this is a Bound session and the lease is a dynamic one. Do not change older reservation
:if (($leaseBound=1) && ([/ip dhcp-server lease find where dynamic mac-address=$leaseActMAC]!="")) do {

# Get the lease number
	:local Lease [/ip dhcp-server lease find mac-address=$leaseActMAC]
	
# Get date and time
	:local date [/system clock get date]
	:local time [/system clock get time]
	
# Make the lease static	
	/ip dhcp-server lease make-static $Lease
	
# Add date and time as a comment to show when it was seen first time	
	/ip dhcp-server lease comment comment="$date $time" $Lease
	
# Send a message to the log	
	:log info message="script=dhcp_static server=$leaseServerName IP=$leaseActIP MAC=$leaseActMAC"
}

Untuk membuat Static pada DHCP Lease yang aktif jalankan script ini di New Terminal.

[
:local date [/system clock get date]
:local time [/system clock get time]
:foreach lease in=[/ip dhcp-server lease find dynamic] do={
	/ip dhcp-server lease make-static $lease
	/ip dhcp-server lease comment comment="$date $time" $lease
}
]

Ketika script ini di jalankan di New Terminal semua client yang ada di DHCP Lease akan berubah menjadi static

Baca juga:

Sumber : Forum Mikrotik

6 COMMENTS

  1. halo mas yayan, saya mo minta tolong nih

    Kronologinya :
    saya menempatkan script berikut dalam setiap profil user hotspot.dengan interval 1 hari

    {
    :local usernya $user;
    :if ([/system schedule find name=$usernya]=””) do={
    /system schedule add name=$usernya interval=1d on-event=”/ip hotspot user remove [find name=$usernya]\r\n/ip hotspot active remove [find user=$usernya]\r\n/system schedule remove [find name=$usernya]”
    }
    }

    nah, tolong dong di tambahkan scriptnya agar supaya dalam on event scheduler menghapus dhcp lease user hotspot sesuai interval waktunya. Dalam hal ini 1d.

    Terima kasih atas bantuannya

    • kira-kira seperti ini,di script ditambahkan dulu variable mac yg diambil dari user hotspot,kemudian ada perintah buat hapus dhcp leases berdasarkan mac tadi

      {
      :local mac $”mac-address”;
      :local usernya $user;
      :if ([/system schedule find name=$usernya]=””) do={
      /system schedule add name=$usernya interval=1d on-event=”/ip hotspot user remove [find name=$usernya]\r\n/ip hotspot active remove [find user=$usernya]\r\n/system schedule remove [find name=$usernya]\r\n/ip dhcp-server lease remove [find mac-address=$mac]”
      }
      }

  2. assalamu’alaikum wr wb,
    mas yayan, mohon maaf kira kira keuntungan dari penerapan di atas apa ya?
    saya ada kasus conflict by arp. kira kira dengan diterapkan seperti di atas bisa lebih baik kah?
    terimakasih
    wassalam

  3. oiya mas yayan,, yang ganteng 🙂
    mas yayan, mau request dong netwact ke telegram untuk log warning..
    terimakasih..
    ditiunggu ya mas

  4. Mas mau tanya, kalau otomatiskan IP binding pada host di menu hotspot apakah ada skripnya?
    sebab mikrotik saya masih versi lama jadi tidak ada fitur MAC Cokie. makanya agak repot kalau ada pelanggan baru yang baru login harus di binding manual.

Leave a Reply Cancel reply