Ka'b (may Allah have mercy on him) says that it is narrated from Sayyiduna Suhayb (may Allah be pleased with him) that whenever the Prophet (peace and blessings be upon him) saw a town he intended to enter, he would say: 'Allahumma rabba al-samawati al-sab'i wa ma azlalna, wa rabba al-aradina al-sab'i wa ma aqlalna, wa rabba al-shayatini wa ma adlalna, wa rabba al-riyahi wa ma dharayna, fa-inna nas'aluka khayra hadhihi al-qaryati wa khayra ahliha, wa na'udhu bika min sharriha wa sharri ahliha wa sharri ma fiha' (O Allah, Lord of the seven heavens and all that they shade, Lord of the seven earths and all that they carry, Lord of the devils and all that they lead astray, and Lord of the winds and all that they scatter: we ask You for the good of this town and the good of its people, and we seek refuge in You from its evil, the evil of its people and the evil of what is in it.)
(b) Abu Marwan al-Aslami narrates from his father, and he from his grandfather (may Allah be pleased with him), who said: We set out with the Prophet (peace and blessings be upon him) to Khaybar; and he mentioned something similar.
This latter chain is weak.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الحج / 10320