The best way is to use All in One WP Security and Firewall.
- Install and activate the plugin from your admin panel.
- Navigate to “WP Security > Blacklist Manager” section.
- Similar to cPanel, enter individual IP address or a range and block the access.
In addition, you can also block user-agent and comment spammers with this plugin.