I can totally sympathise. I'll know something has to be done, but I'll end up distracting myself with something totally unrelated, almot unable to stop. I still have problems, but I have a few steps I can go through to get me back on track; I hope they'll work for you too.
First, you have to remember to do it - it may sound trivial, but you can easily get so distracted that you'll forget completely about what you're meant to be doing. For this, just keep refreshing what it is that you need to do in your mind; ask yourself every so often what you need and have planned to do. Second, you have to want to do it; and for that, you have to have a reason, preferably one that makes you feel good. So, for your homework, you could say "I want to do well in my schoolwork and be successful"; something like "I have to or I'll fail otherwise" is not as effective. Then, you use the reason to convince yourself to want to do it. You have to think about it and let it affect you emotionally. So, you could perhaps think about how good you'll feel when it's finished in record time, for example - pick anything you want, really. Third, you have to build up motivation. You can want to do something with all your heart and still not have any inclination to do it. For this, you can do various things; I usually do something like closing my eyes and repeating to myself "I want to do this, and when I open my eyes I will fully focus on it until it is done." Do whatever is comfortable for you, and hopefully you will feel a lot more inclined to start and continue until you're finished.
So, there's my method, I hope it helps you. I wish you luck in whatever you want to do