Community discussions

MikroTik App
 
namo
Long time Member
Long time Member
Topic Author
Posts: 530
Joined: Sat Oct 03, 2009 4:44 pm

deassign DHCP for IPs from a list

Mon Dec 13, 2010 9:27 pm

I have Mikrotik v4.14
I want a script that run every 1 hour and check for IPs in a list called "24-hour-list" that I made in the firewall address list. The script should deassign those IP addresses

if the IP is not DHCP, the script should look for ips in the active and hostes of hotspot and remove them.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: deassign DHCP for IPs from a list

Mon Dec 13, 2010 9:40 pm

:foreach ITEM in=[/ip firewall address-list find list="24-hour-list"] do={
  :local IP [/ip firewall address-list get $ITEM address];
  /ip dhcp-server lease remove [/ip dhcp-server lease find address="$IP";
  /ip hotspot active remove [/ip hotspot active find address="$IP"];
  /ip hotspot hosts remove [/ip hotspot hosts find address="$IP"];
}
Untested, but that should work.

Keep in mind that just removing a DHCP lease from the lease list doesn't actually do anything to the client. The server cannot signal to the client that an IP lease should no longer be used - that isn't part of of the DHCP protocol. The server will ARP for what is perceived as a free lease before assigning it to a new client, the old client will respond and the IP address will be unavailable as a lease.
 
namo
Long time Member
Long time Member
Topic Author
Posts: 530
Joined: Sat Oct 03, 2009 4:44 pm

Re: deassign DHCP for IPs from a list

Mon Dec 13, 2010 10:24 pm

The list actually coming from the fallowing firewall rule that I get from somewhere saying that anybody use netcut will be in the list.

I want to deassign the ip so the real user get another IP and he has to login again
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: deassign DHCP for IPs from a list

Mon Dec 13, 2010 10:32 pm

You can't force the client to immediately choose a new DHCP lease - that simply isn't how DHCP works. Also note that the client will, after 50% of the lease time has passed, try to renew the lease he had before. The DHCP server will usually honor that request if the lease is available and the client does not get a new DHCP lease even if you removed the existing one.
http://www.tech-faq.com/dhcp-leasing.html describes how DHCP works - because the client had a lease before it doesn't repeat the discover phase and goes straight to a request for the IP address it already has.

While you could theoretically build a DHCP server that fulfills your requirements I am fairly certain that the RouterOS one cannot be used in the way you want it to behave. I'm not aware of existing third party options, either.
 
namo
Long time Member
Long time Member
Topic Author
Posts: 530
Joined: Sat Oct 03, 2009 4:44 pm

Re: deassign DHCP for IPs from a list

Mon Dec 13, 2010 11:01 pm

thank you few

I am still thinking of a way to prevent netCut. This method might annoy the real user. In my server the netcut user need to get the mac address and he wll be using internet for free. That;s why the real user says the internet always slow.

I am thinking of moving to PPPoE but my users are always paying late and they need frequent reminder (advertisement in hotspot). Another good thing in hotspot that there is comment where you can put real first and last name of the user so you don't need extra documents to keep track of username<-----> real name match up.

In my area there are five hotspot provider and all can be used for free with the help of Netcut.

I will see if the situation improve after installing a a managed switch but the problem that will remain is what to do about the old netCut users who store a few mac and IP for real users that stay online for long time.

Thank you again Few for your help
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: deassign DHCP for IPs from a list

Mon Dec 13, 2010 11:06 pm

It's still my opinion that you are wasting time and will not find a solution.

Good luck, though.
 
namo
Long time Member
Long time Member
Topic Author
Posts: 530
Joined: Sat Oct 03, 2009 4:44 pm

Re: deassign DHCP for IPs from a list

Tue Dec 14, 2010 4:45 am

there might be code or trick to reduce them. I want just to prevent netcut not a pro program. I am worried about netCut because even normal user can use it easly.

Another thing that I notice that when real user login he assigned IP from DHCP and when the netCut guy change his MAC, DHCP deassign the IP from the real user and assign it to the Netcut guy. I know this because the active host name in DHCP server change. Can we use this fact to block active host name of that user and tell any one who has the same active host name by chance to change it.

Who is online

Users browsing this forum: No registered users and 10 guests