The one who has a septic wound should do whatever it takes to remove the poison and heal the wound, with antidotes and ointments. This may be achieved in several ways, such as:
Getting married, because the Prophet (peace and blessings of Allah be upon him) said: “If one of you sees the charms of a woman, let him come to his wife, for she has the same as (the other woman).” This will reduce desire and weaken the infatuation.
Persisting in offering the five daily prayers, engaging in du’a and beseeching Allah during the period before dawn. His prayer should be offered with proper presence of mind and focus. He should make a lot of du’a such as “Ya muqallib al-quloob thabbit qalbi 'ala deenik (O Controller of the hearts, make my heart adhere firmly to Your religion)” and “Ya musarrif al-quloob, sarrif qalbi ila ta’atika wa ta’ati rasoolika (O Director of the hearts, direct my heart to obey You and Your Messenger).” If he persists in du’a and beseeching Allah, He will direct his heart away from that, as Allah says (interpretation of the meaning): “Thus it was, that We might turn away from him evil and illegal sexual intercourse. Surely, he was one of Our chosen, (guided) slaves” [Yoosuf 12:24].
End quote from al-Fatawa al-Kubra (3/77) by Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him).
Keeping away from places where there are adorned women, and TV channels and so on that show images that may affect and weaken the heart.
And Allah knows best.