Anas (may Allah be pleased with him) narrates that the Prophet of Allah (may Allah be pleased with him) said: “The person who performs marriage [nikah] with his hands (i.e. masturbates) is cursed.” (Fatawa Razaviyya, Vol. 10, p.80)
And Quran says the same:
5 And those who guard their chastity (i.e. private parts, from illegal sexual acts)
6 Except from their wives or (the slaves) that their right hands possess, - for then, they are free from blame;
The exception is only wife and guarding chastity means guarding from masturbation.
Hence its haram.
Instead you are commaded to fast as it diminishes sexual power.