Changeset View
Changeset View
Standalone View
Standalone View
src/app/Utils.php
Show First 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | public static function ip6Broadcast($net, $prefix) | ||||
$lastAddrHex = substr_replace($lastAddrHex, $new, $pos, 1); | $lastAddrHex = substr_replace($lastAddrHex, $new, $pos, 1); | ||||
// We processed one nibble, move to previous position | // We processed one nibble, move to previous position | ||||
$flexbits -= 4; | $flexbits -= 4; | ||||
$pos -= 1; | $pos -= 1; | ||||
} | } | ||||
// Convert the hexadecimal string to a binary string | // Convert the hexadecimal string to a binary string | ||||
# Using pack() here | // Using pack() here, newer PHP version can use hex2bin() | ||||
# Newer PHP version can use hex2bin() | |||||
$lastaddrbin = pack('H*', $lastAddrHex); | $lastaddrbin = pack('H*', $lastAddrHex); | ||||
// And create an IPv6 address from the binary string | // And create an IPv6 address from the binary string | ||||
$lastaddrstr = inet_ntop($lastaddrbin); | $lastaddrstr = inet_ntop($lastaddrbin); | ||||
return $lastaddrstr; | return $lastaddrstr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | public static function randStr($length, $qty = 1, $join = '') | ||||
$randStrs[$x] = implode('', $randStrs[$x]); | $randStrs[$x] = implode('', $randStrs[$x]); | ||||
} | } | ||||
return implode($join, $randStrs); | return implode($join, $randStrs); | ||||
} | } | ||||
/** | /** | ||||
* Returns the IP address of the HTTP request | |||||
* | |||||
* @return string IP address | |||||
*/ | |||||
public static function requestIp() | |||||
{ | |||||
// TODO: Verify if it works with proxies | |||||
return request()->ip(); | |||||
} | |||||
/** | |||||
* Returns a UUID in the form of an integer. | * Returns a UUID in the form of an integer. | ||||
* | * | ||||
* @return integer | * @return integer | ||||
*/ | */ | ||||
public static function uuidInt(): int | public static function uuidInt(): int | ||||
{ | { | ||||
$hex = Uuid::uuid4(); | $hex = Uuid::uuid4(); | ||||
$bin = pack('h*', str_replace('-', '', $hex)); | $bin = pack('h*', str_replace('-', '', $hex)); | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |