Keyboard Maestro: How to write to /etc/hosts file
Have Keyboard Maestro run an AppleScript, which runs a shell script, which changes your hosts file:

do shell script "cp ~/hosts.tmp /etc/hosts" with administrator privileges


Simple! :)

The "with administrator privileges" part will cause it to prompt you for the sudo password.