Fiqh-us-Sunnah Volume 4, Funerals and Dhikr, Fiqh 4.147.
‘Ata ibn Abi Marwan relates from his father that Ka’ab swore to him by Him Who split the sea for Prophet Moses, peace be upon him, that Suhaib informed him that whenever the Prophet, peace be upon him, saw a village that he wanted to enter, he always supplicated, “Allahumma rabbis samawati sab’ i wa ma azlalna wa rabbul ardinas sab’ i wa ma aqlalna wa rabbush sayatini wa ma adlalna wa rabbur riyyahi wa ma zaraina as’aluka khaira hazhihil qaryata wa khaira ahlaha wa khaira mafiha wa na’uzhu bika min sharriha wa sharri ahliha wa sharri mafiha (O Allah, Lord of the seven heavens and what they overshadow, Lord of the seven earths and what they carry, and Lord of the devils and those whom they mislead, and Lord of the winds and what they scatter about, I ask You of the good of this village, the good of its people and the good it has, and seek Your protection from its evil, and the evil of its people, and the evil in it).” (Reported by Nasa’i, Ibn Hibban, and Al-Hakim who considers this a sound hadith)
Ibn ‘Umar reported, “We were with the Prophet, peace be upon him, on a journey. When he saw a town that he wanted to enter he would say, ‘O Allah, bless us in it’ three times, and then ‘O Allah grant us sustenance from its fruits, and put our love in (the hearts of) its people, and put the love of its righteous people in our hearts’.” (Reported by At-Tabarani in his Al-Awsar with a sound chain of authorities)
A’ishah reported that whenever the Prophet, peace be upon him, approached a place that he intended to enter he would say, ‘O Allah I ask You of the good in it, and the good of what you have placed in it, and I seek Your refuge from its evil and the evil of what You have placed in it. O Allah, give us its fruits and protect us from its plagues, and put our love in the hearts of its people and put the love of its righteous people in our hearts.’ (Reported by As-Sinni)