I assume you set "$Dynamicip" to "2" somewhere in your script?

Which part isn't working, checking that a client is using DHCP or setting the proxy values?