The threat posed by false base stations remains pertinent across the 4G, 5G, and forthcoming 6G generations of mobile communication. In response, this paper introduces a real-time detection method for false base stations employing two approaches: machine learning and specification-based. Utilizing the UERANSIM open 5G RAN (Radio-Access Network) test platform, we assess the feasibility and practicality of applying these techniques within a 5G network environment. Emulating real-world 5G conditions, we implement a functional split in the 5G base station and deploy the False Base Station Detection Function (FDF) as a 5G NF (Network Function) within the CU (Central Unit). This setup enables real-time detection seamlessly integrated into the network. Experimental results indicate that specification-based detection outperforms machine learning, achieving a detection accuracy of 99.6% compared to 96.75% for the highest-performing machine learning model XGBoost. Furthermore, specification-based detection demonstrates superior efficiency, with CPU usage of 1.2% and memory usage of 16.12MB, compared to 1.6% CPU usage and 182.4MB memory usage for machine learning on average. Consequently, the implementation of specification-based detection using the proposed method emerges as the most effective technique in the 5G environment.