Functions.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Helpers;
  3. class Functions{
  4. public static function getIp(){
  5. foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){
  6. if (array_key_exists($key, $_SERVER) === true){
  7. foreach (explode(',', $_SERVER[$key]) as $ip){
  8. $ip = trim($ip);
  9. if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){
  10. return $ip;
  11. }
  12. }
  13. }
  14. }
  15. return request()->ip();
  16. }
  17. public static function UniqueMachineID($salt = "") {
  18. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  19. $temp = sys_get_temp_dir().DIRECTORY_SEPARATOR."diskpartscript.txt";
  20. if(!file_exists($temp) && !is_file($temp)) file_put_contents($temp, "select disk 0\ndetail disk");
  21. $output = shell_exec("diskpart /s ".$temp);
  22. $lines = explode("\n",$output);
  23. $result = array_filter($lines,function($line) {
  24. return stripos($line,"ID:")!==false;
  25. });
  26. if(count($result)>0) {
  27. $result = array_shift(array_values($result));
  28. $result = explode(":",$result);
  29. $result = trim(end($result));
  30. } else $result = $output;
  31. } else {
  32. $result = shell_exec("blkid -o value -s UUID");
  33. if(stripos($result,"blkid")!==false) {
  34. $result = $_SERVER['HTTP_HOST'];
  35. }
  36. }
  37. return md5($salt.md5($result));
  38. }
  39. }