Core–shell poly(2,3-dimethylaniline)/organic-attapulgite (P(2,3-DMA)/APTES-ATP) nanofibers were prepared by self-assembling and graft polymerization in the presence of organically modified attapulgite, based on the encapsulation of attapulgite (ATP) template with P(2,3-DMA) after the surface modification with γ-aminopropyltriethoxysilane (APTES) to form a self-assembled layer on the surface of ATP rod-shaped particle (APTES-ATP). Structure, morphology and thermal stability of the nanocomposites were characterized by XRD, FTIR, SEM, TEM and TGA measurements, respectively. The anticorrosion property of the as-prepared nanocomposites was evaluated by open circuit potential (OCP) and impedance spectroscopy (EIS) in 3.5 wt% NaCl aqueous solution. Experimental results indicated that P(2,3-DMA)/APTES-ATP had a more higher thermal stability and anti-corrosion properties compared with the bulk poly(2,3-dimethylaniline) (P(2,3-DMA)).