Software-defined networking (SDN) is a contemporary structural design paradigm that aspires to correct bandwidth-efficient usage and user application transparent interoperability. It claims to be self-motivated, convenient, affordable, and programmable. The network control may become directly programmable thanks to SDN architecture's decoupling of the network control and management plane from the data plane. Due to the centralized architecture of the SDN network, message propagation to various network devices in SDN is delayed. The SDN controller must thus establish new rules for each new communication. Peer-to-peer protocols are deployed in the system for the fast propagation of contents over the layered architecture. However, these protocols produce unwanted packets because these protocols mostly use a reactive routing protocol over an SDN architecture. This causes the delay for different applications due to inefficient bandwidth management. By offering resistance to connection failures and accommodating constantly changing bandwidth needs, it is difficult to control the needed bandwidth. This paper proposes a new technique using the Random Forest algorithm for efficient bandwidth management for peer-to-peer applications. In this technique, bandwidth usage of different applications is computed and predicted. So, according to the need of applications, network traffic is adjusted accordingly. An ultra-peer node is responsible for communication with other nodes in this methodology, eliminating unwanted traffic across the network. A Linux-based OpenvSwitch, POX controller and Mininet-based SDN-based network system are used for the tests. The results of the experiment demonstrate that the proposed framework may significantly improve QoS while outperforming the current bandwidth allocation algorithms in terms of success rate, throughput, response time, etc.