The structural, electronic and nonlinear optical properties of the two important fullerene-like cages of B12N12 and Al12N12 nanostructures with the groups III, IV and V dopants are investigated through density functional theory (DFT) calculations. It has been found that doping process induces local deformation at bond lengths near the doping site. Natural bond orbital (NBO) analyses are also performed for scrutinizing the structural properties of the considered nanoclusters. The results indicate that the groups III, IV and V dopants remarkably narrow the energy gap of the B12N12 nanocluster. On the other hand, although the energy gap of Al12N12 nanocluster is insensitive to groups III and V dopants; the carbon, silicon and germanium dopants extremely reduce the energy gap of this cluster. It seems that the electronic character of the B12N12 and Al12N12 nanocluster is sensitive to the dopants and it could be adjusted by particular impurity. Moreover the considered dopants induce hyperpolarizability in both of the considered nanoclusters. Interestingly, the replacing aluminum atom by carbon one in Al12N12 nanocluster (CAl11N12) leads to an extremely large hyperpolarizability value of 4358.77a.u., which is the largest one among the considered doped clusters. It shows that the doping process plays an important role in enhancing the first hyperpolarizability of the B12N12 and Al12N12 nanoclusters.