How can I switch DHCP on/off in runtime

Is this sample for IPV6?
Can you tell me for IPV4?