The band structures of photonic crystals can be described by the shifted Maxwell eigenproblem. Compared with the Laplace eigenproblem, the main difficulty in computing the discrete Maxwell eigenproblem is to deal with its huge kernel, especially when computing large-scale problems with iterative methods. In this paper, we discretize the shifted Maxwell operator with edge finite element spaces and construct a penalty term using Lagrange finite element spaces. Using the properties of the finite element spaces on the discrete de Rham complex, we prove that this penalty term can complement the kernel of the discrete Maxwell operator. Then the discrete Maxwell eigenproblem with the penalty term can be computed almost in the same way as for the Laplace eigenproblem. The difficulties caused by the huge kernel of the Maxwell operator are avoided. Many efficient methods and techniques for the Laplace eigenproblem can be easily applied in computing the Maxwell eigenproblem. We also prove that the nonzero eigenpairs of the original discrete Maxwell eigenproblem are free from the impact of the penalty term and can be recovered by a simple recomputation. The desired solutions of the original problems can be identified from the solutions of the auxiliary problems. The requirement for the parameter of the penalty term is to make the auxiliary eigenproblem suitable for the selected iterative eigensolvers. We design a matrix-type preconditioner for the algorithm to reduce the iteration count of the iterative eigensolver. Most parts of the algorithm are basic matrix and vector operators, which are of fine-grained parallelism and can be easily accelerated by GPU. Numerical examples for the band structures of 3D photonic crystals are presented to demonstrate the capability and efficiency of the algorithm.