HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pma.bikenow.co/libraries/classes/Utils/FormatConverter.php
<?php
/**
 * Format converter
 */

declare(strict_types=1);

namespace PhpMyAdmin\Utils;

use PhpMyAdmin\Util;
use function bin2hex;
use function hex2bin;
use function inet_ntop;
use function inet_pton;
use function ip2long;
use function long2ip;
use function strpos;
use function substr;

/**
 * Format converter
 */
class FormatConverter
{
    /**
     * Transforms a binary to an IP
     *
     * @param mixed $buffer Data to transform
     *
     * @return false|string
     */
    public static function binaryToIp($buffer)
    {
        if (strpos($buffer, '0x') !== 0) {
            return $buffer;
        }

        $ipHex = substr($buffer, 2);
        $ipBin = hex2bin($ipHex);

        if ($ipBin === false) {
            return $buffer;
        }

        return @inet_ntop($ipBin);
    }

    /**
     * Transforms an IP to a binary
     *
     * @param mixed $buffer Data to transform
     *
     * @return string
     */
    public static function ipToBinary($buffer)
    {
        $val = @inet_pton($buffer);
        if ($val !== false) {
            return '0x' . bin2hex($val);
        }

        return $buffer;
    }

    /**
     * Transforms an IP to a long
     *
     * @param string $buffer Data to transform
     *
     * @return int|string
     */
    public static function ipToLong(string $buffer)
    {
        $ipLong = ip2long($buffer);
        if ($ipLong === false) {
            return $buffer;
        }

        return $ipLong;
    }

    /**
     * Transforms a long to an IP
     *
     * @param mixed $buffer Data to transform
     */
    public static function longToIp($buffer): string
    {
        if (! Util::isInteger($buffer) || $buffer < 0 || $buffer > 4294967295) {
            return $buffer;
        }

        return (string) long2ip((int) $buffer);
    }
}