Ref. No. 41/849
In the name of Allah the most Gracious the most Merciful
The answer to your question is as follows:
One is not allowed to go though such dirty act in any case. If one is under extreme excitement, he is obliged to marry a suitable girl in simple way at earliest. Nevertheless, when a person has no means to marry, he should use other means to avoid excitement and he should consult a Hakeem or Doctor for treatment. Meanwhile he should keep in touch with a pious person (sheikh) and read Wazifa to reduce his excitement. One has to lower his gazes too and must not look at girls. May Allah protect us from evil acts! Ameen
And Allah knows best
Darul Ifta
Darul Uloom Waqf Deoband