Files
Alex Justesen 7826d8be3e [Feature] Skip test when Public IP is in a list (#1714) (#1795)
* [Feature] Skip test when Public IP is in an list (#1714)

* first commit

* Commit it

* lint

* update-all-charts

* push_local_git

* add-timepicker

* add-some-predefined-ranges

* remove whiteline

* Add_env_for_chart_start

* change-env-and_time-ranges

* change_average_to_orange

* Revert "Add failed and thresholds"

* first commit

* change_api

* update comments

* Simplify

* Seperate the IP check

* extracted get external ip address to reusable action

* moved ip in range to network helper

* made skip ips config plural

* refactored speedtest job to use actions and helpers

* always show data message

* removed dup code

* fixed capturing error message

---------

Co-authored-by: Sven van Ginkel <svenvanginkel@icloud.com>
2024-11-20 07:12:46 -05:00

23 lines
477 B
PHP

<?php
namespace App\Helpers;
class Network
{
/**
* Check if the given ip is in a network range.
*/
public static function ipInRange(string $ip, string $range): bool
{
[$range, $mask] = explode('/', $range) + [1 => '32'];
$rangeDecimal = ip2long($range);
$ipDecimal = ip2long($ip);
$maskDecimal = ~((1 << (32 - (int) $mask)) - 1);
return ($rangeDecimal & $maskDecimal) === ($ipDecimal & $maskDecimal);
}
}