PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.0
Defender Security – Malware Scanner, Login Security & Firewall v5.7.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / component / known-bots / bots / class-bing-bot.php

class-bing-bot.php in Defender Security – Malware Scanner, Login Security & Firewall 5.7.0, at src/component/known-bots/bots/class-bing-bot.php

52 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Fetches Bing Bot IPs.
4 *
5 * @package WP_Defender\Component\Known_Bots\Bots
6 */
7
8 namespace WP_Defender\Component\Known_Bots\Bots;
9
10 /**
11 * This class is responsible for fetching and managing Bing Bot IPs.
12 */
13 class Bing_Bot implements Bots_Interface {
14 /**
15 * Returns the name of the bot.
16 *
17 * @return string The name of the bot.
18 */
19 public function get_name(): string {
20 return 'bingbot';
21 }
22
23 /**
24 * Fetches the IPs for Bing Bot.
25 *
26 * This method retrieves the IP ranges used by Bing Bot from a remote JSON endpoint.
27 * It returns an array of IP addresses in both IPv4 and IPv6 formats.
28 *
29 * @return array An array of IP addresses used by Bing Bot.
30 */
31 public function fetch_ips(): array {
32 $url = 'https://www.bing.com/toolbox/bingbot.json';
33 $ips = array();
34
35 $response = wp_remote_get( $url );
36 if ( is_array( $response ) && ! is_wp_error( $response ) ) {
37 $data = json_decode( wp_remote_retrieve_body( $response ), true );
38 foreach ( $data['prefixes'] ?? array() as $entry ) {
39 if ( isset( $entry['ipv4Prefix'] ) ) {
40 $ips[] = $entry['ipv4Prefix'];
41 }
42
43 if ( isset( $entry['ipv6Prefix'] ) ) {
44 $ips[] = $entry['ipv6Prefix'];
45 }
46 }
47 }
48
49 return $ips;
50 }
51 }
52