Well I have two approaches to overcoming any addiction or habit I want to curb...
First, (Which only works if you have self discipline) the problem is your productive behaviors are getting compromised by your more enjoyable behaviors. Set yourself a rule (write it down) on how much distraction is allowed, if you violate that distraction you punish yourself (with something else productive that you want to do even less). We humans often become willing to do something we really don't want to when presented with something we want to do even less.
Second, (better if you're less self disciplined) remove the temptation. (But Rual, I NEED the internet for what I'm doing, how do I remove temptation I require?) Simple: there are these wonderfully evil tools to restrict where you can go to on the internet. The cheapest is to modify your hosts file (if you're tech savvy, I'm assuming you are) otherwise just grab a free proxy filter or parental control system. (yes, you're about to treat yourself like a child and take away your own toys.)
Whatever your online vice is goes into the blocked bin. Anytime you find yourself distracted with something that isn't productive during time you've allocated to be productive it goes on the list. When sit down to be productive, turn on the filter. Now in order to be bad you need to explicitly disable the filter. Make a VERY stern, non-negotiable, written down punishment for doing this. (Preferably something productive, like volunteering 4 hours to a local charity per incident, which is an excellent and socially beneficial thing.) Once you realize you broke your rule, make time to punish yourself. (Slightly masochistic, but it works.) Of course... if you follow through with your punishment and still misbehave you have to increase the punishment.
If all else fails you are left with the scorched earth approach... turn on your overzealous filter, have someone you trust take control of the filter so you can no longer disable it without them. (Making the filter on by default) you lose your right to these things you enjoy and have to earn them as a privilege. (It doesn't sound like your problem has reached this severity, but some addictions cannot be beaten alone, sometimes we need to have our addictions taken from us completely to free ourselves from them.)
Hope this helps, at least you realize you have a problem. Recognizing the problem is the first step in solving it.