One of the best things that helped when I was first starting out was something I found in a great book called "The Willpower Instinct" by Kelly Mcgonagall. I highly recommend it for any sort of willpower struggle you may have. Anyway, one of her best tips is called "The 10 minutes rule" - whenever you feel the urge to do indulge in something you know is bad for you - in this case, looking up non-tznua stuff online or masturbating and such - but also helps with eating urges (practically anything, really) - instead of telling yourself: "No!", tell yourself: "Yes, but in 10 minutes." Actually say this to yourself, don't just think it. Then, before the time is up - you've got a few minutes of clarity to go take a walk or something. More than that, this time should be used to strengthen yourself in face of that annoying little voice telling you to indulge: Remind yourself how important it is for you to be strong, how much better your life will be if you don't fall, etc.
B"H this idea has helped me - and still does - tremendously.
Once you get that moment of clarity - you can pick yourself up and go for a nice, calming 20-30 minute walk. Listen to a shiur or a podcast, or even don't listen to anything but concentrate on your thoughts.