Find your real motivation
For some people, it could be boredom; for some others, it could be for entertainment or connections. Different people have different reasons for constantly using the social media or internet. You have to identify the cause of this problem before you can know how to tackle it.
Make a record of dates and times
Learn to write down dates and times you turn on your computer or any other device, to use the internet. If you keep record of this, you will realize how much time you've spent, when you could have done something more profitable.
Ask for help from a trusted source
This is yet another way to deal with it. Talk to someone about your problem; not just anyone, but someone you trust would have a solution; it could be a friend, or a close relative, or even a professional. Let the person know how much you are into social media and the internet, and he/she could talk some sense into you that could motivate and change your lifestyle
Know your common sites and social media accounts
You need to identify the websites you visit often and the social media you make use of the most. You may be more into Facebook than you are into Twitter or it could be that comic website that takes all your time. After identifying them, start seeing them as time-exhausting, and learn to keep away from them as much as possible.
Turn off your notifications
Notifications will always pop up and tempt you to get distracted. Ignoring them might not be all that easy, so it's best you turn of your notifications completely; that way, you are controlling the urge to reach the internet or social media.
Get rid of counterproductive accounts and websites
Sometimes, the only way to get over something is to cut it off completely. You can decide to deactivate your Facebook account and delete the app, to resist the urge to activate it back. You can block those affectionate sites on your browser, such that you have no access to them.
Time yourself; limit the amount of time you spend using the internet in a day. You could dedicate an hour out of your 24hours, to social media and internet, unless if there is an emergency. Set a timer, such that once your time is up, you are already vacating the social media and internet space.
If you have nothing relevant doing, there are chances that you will crawl back into the social media and internet again. Get yourself engaged, and make proper use of your time. It could be art, reading, learning a new skill, or even signing up in a gym.