Here is a link to an article on Shaban.
http://www.islamicity.org/6005/to-fast-or-not-to-fast-in-shaban/" rel="nofollow - http://www.islamicity.org/6005/to-fast-or-not-to-fast-in-shaban/
For Rajab, see the following note:
Some people asked about fasting in the month of Rajab
In the seven books of ahadith there are at least three statements attributed to the Prophet. One asserts that the Prophet forbade fasting in the month of Rajab, while the other two says it is recommended. Here are the ahadith.
Ibn ‘Abbas reported that:
The Prophet (ﷺ) forbade fasting Rajab as reported in Ibn Maja collection Book 7 and the hadith no 1815.
حَدَّثَنَا إِبْرَاهِيمُ بْنُ الْمُنْذِرِ الْحِزَامِيُّ، حَدَّثَنَا دَاوُدُ بْنُ عَطَاءٍ، حَدَّثَنِي زَيْدُ بْنُ عَبْدِ الْحَمِيدِ بْنِ عَبْدِ الرَّحْمَنِ بْنِ زَيْدِ بْنِ الْخَطَّابِ، عَنْ سُلَيْمَانَ، عَنْ �£َبِيهِ، عَنِ ابْنِ عَبَّاسٍ، �£َنَّ النَّبِيَّ ـ صلى الله عليه وسلم ـ نَهَى عَنْ صِيَامِ رَجَبٍ .
However in Sahih Muslim book 13 hadith 232, 'Uthman b. Hakim al-Ansari said:
I asked Sa'id b. Jubair about fasting In Rajab, and we were then passing through the month of Rajab, whereupon he said: I heard Ibn 'Abbas (Allah be pleased with both of them) as saying: The Messenger of Allah (ﷺ) used to observe fast (so continuously) that we (were inclined) to say that he would not break (them) and did not observe them so conti- nuously) that we (were inclined to say) that he would not observe fast.
حَدَّثَنَا �£َبُو بَكْرِ بْنُ �£َبِي شَيْبَةَ، حَدَّثَنَا عَبْدُ اللَّهِ بْنُ نُمَيْرٍ، ح وَحَدَّثَنَا ابْنُ نُمَيْرٍ، حَدَّثَنَا �£َبِي، حَدَّثَنَا عُثْمَانُ بْنُ حَكِيمٍ ال�£َنْصَارِيُّ، قَالَ سَ�£َلْتُ سَعِيدَ بْنَ جُبَيْرٍ عَنْ صَوْمِ، رَجَبٍ - وَنَحْنُ يَوْمَئِذٍ فِي رَجَبٍ - فَقَالَ سَمِعْتُ ابْنَ عَبَّاسٍ - رضى الله عنهما - يَقُولُ كَانَ رَسُولُ اللَّهِ صلى الله عليه وسلم يَصُومُ حَتَّى نَقُولَ لاَ يُفْطِرُ . وَيُفْطِرُ حَتَّى نَقُولَ لاَ يَصُومُ
In Sunan Abu Dawood, Book 14 and hadith 118 Narrated 'Uthman b. Hakim narrates from a different chain of narrators that:
I asked Sa'id b. Jubair about fasting during Rajab. He said: Ibn 'Abbas told me that the Messenger of Allah (ﷺ) used to fast to such an extent that we thought that he would never break his fast; and he would go without fasting to such an extent that we thought he would never fast.
حَدَّثَنَا إِبْرَاهِيمُ بْنُ مُوسَى، حَدَّثَنَا عِيسَى، حَدَّثَنَا عُثْمَانُ، - يَعْنِي ابْنَ حَكِيمٍ - قَالَ سَ�£َلْتُ سَعِيدَ بْنَ جُبَيْرٍ عَنْ صِيَامِ رَجَبَ، فَقَالَ �£َخْبَرَنِي ابْنُ عَبَّاسٍ، �£َنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم كَانَ يَصُومُ حَتَّى نَقُولَ لاَ يُفْطِرُ وَيُفْطِرُ حَتَّى نَقُولَ لاَ يَصُومُ .
Some scholars call one or the other hadith weak and then give a ruling
How can we avoid this confusion? The prophet recommended fasting on Mondays and Thursdays. Let us agree on that regardless of the month. Those who want to fast in Rajab can fast on Mondays and Thursdays even those who assert that fasting is forbidden in Rajab. Those who believe that they should fast in Rajab can add other days in addition to Mondays and Thursdays as part of the general recommendations of the Prophet.