Recent experiments identified Co3Sn2S2 as the first magnetic Weyl semimetal (MWSM). Using first-principles calculation with a global optimization approach, we explore the structural stabilities and topological electronic properties of cobalt (Co)-based shandite and alloys, Co3MM’X2 (M/M’ = Ge, Sn, Pb, X = S, Se, Te), and identify stable structures with different Weyl phases. Using a tight-binding model, for the first time, we reveal that the physical origin of the nodal lines of a Co-based shandite structure is the interlayer coupling between Co atoms in different Kagome layers, while the number of Weyl points and their types are mainly governed by the interaction between Co and the metal atoms, Sn, Ge, and Pb. The Co3SnPbS2 alloy exhibits two distinguished topological phases, depending on the relative positions of the Sn and Pb atoms: a three-dimensional quantum anomalous Hall metal, and a MWSM phase with anomalous Hall conductivity (~1290 Ω−1 cm−1) that is larger than that of Co2Sn2S2. Our work reveals the physical mechanism of the origination of Weyl fermions in Co-based shandite structures and proposes topological quantum states with high thermal stability.