Fiqh-us-Sunnah Volume 4, Funerals and Dhikr, Fiqh 4.127.

Section : On Hearing the Sound of a Cock, a Donkey, and a Dog.

Abu Hurairah reported that the Prophet, peace be upon him, said, -Seek refuge with Allah against the devil when you hear the sound of a donkey, for it sees the devil, and when you hear a cock, pray to Allah for His bounty, for it sees an angel.’ (Bukhan and Muslim)

Abu Daw’ud’s version reads, “When you hear the barking of dogs and braying of donkeys during the night seek the refuge of Allah from them, for they see what you don’t.”