script to limit a particular ip address

hi,

i am trying to make a script to limit the bandwidth of particular ip address, the thing is that it will not always be the same ip, i need to check if the download speed of an interface meets certain threshold, and limit the ip address causing the overuse in that moment for an amont of time. same thing for upload.

thanks a lot in advanced for every advice.