The research explores the problem of Distributed Denial of Service (DDoS) attacks in Software Defined Networks (SDN) and proposes a Network Detection and Prevention Agent (NDPA) algorithm that utilizes SDN capabilities for effective traffic control and recovery. Simulation results indicate that the NDPA successfully mitigates DDoS attacks while maintaining service quality, allowing for communication between the server and SDN controllers. The study highlights the sophistication of the proposed solution and its focus on separating duties among components to improve the overall resilience against attacks.