One thing I've found useful is just to stop and think about what I'm doing and why I'm doing it every hour or so.
Much of the time the answer becomes "browsing the internet because I'm bored" and the conscious act of thinking about it allows corrective action to be taken. Even if I don't want to work, I can at least do something constructive like some chores instead of wasting time.