It is narrated from Sayyiduna Samurah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "When one of you passes by livestock, let him call out three times; if someone answers (let him ask permission), otherwise let him milk and drink."
Hadith Referenceالمعجم الكبير للطبراني / باب السين / 6848