Advertisement
FingerMyHash

Untitled

May 21st, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. function get_ip_address()
  2. {
  3. if (!empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) {
  4. return $_SERVER['HTTP_CLIENT_IP'];
  5. }
  6. if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  7. if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
  8. $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  9. foreach ($iplist as $ip) {
  10. if (validate_ip($ip))
  11. return $ip;
  12. }
  13. } else {
  14. if (validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']))
  15. return $_SERVER['HTTP_X_FORWARDED_FOR'];
  16. }
  17. }
  18. if (!empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED']))
  19. return $_SERVER['HTTP_X_FORWARDED'];
  20. if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
  21. return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
  22. if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR']))
  23. return $_SERVER['HTTP_FORWARDED_FOR'];
  24. if (!empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED']))
  25. return $_SERVER['HTTP_FORWARDED'];
  26. return $_SERVER['REMOTE_ADDR'];
  27. }
  28.  
  29. function ip_in_range($ip, $range) {
  30. if (strpos($range, '/') == false)
  31. $range .= '/32';
  32.  
  33. list($range, $netmask) = explode('/', $range, 2);
  34. $range_decimal = ip2long($range);
  35. $ip_decimal = ip2long($ip);
  36. $wildcard_decimal = pow(2, (32 - $netmask)) - 1;
  37. $netmask_decimal = ~ $wildcard_decimal;
  38. return (($ip_decimal & $netmask_decimal) == ($range_decimal & $netmask_decimal));
  39. }
  40.  
  41. function _cloudflare_CheckIP($ip) {
  42. $cf_ips = array(
  43. '199.27.128.0/21',
  44. '173.245.48.0/20',
  45. '103.21.244.0/22',
  46. '103.22.200.0/22',
  47. '103.31.4.0/22',
  48. '141.101.64.0/18',
  49. '108.162.192.0/18',
  50. '190.93.240.0/20',
  51. '188.114.96.0/20',
  52. '197.234.240.0/22',
  53. '198.41.128.0/17',
  54. '162.158.0.0/15',
  55. '104.16.0.0/12',
  56. );
  57. $is_cf_ip = false;
  58. foreach ($cf_ips as $cf_ip) {
  59. if (ip_in_range($ip, $cf_ip)) {
  60. $is_cf_ip = true;
  61. break;
  62. }
  63. } return $is_cf_ip;
  64. }
  65.  
  66. function _cloudflare_Requests_Check() {
  67. $flag = true;
  68.  
  69. if(!isset($_SERVER['HTTP_CF_CONNECTING_IP'])) $flag = false;
  70. if(!isset($_SERVER['HTTP_CF_IPCOUNTRY'])) $flag = false;
  71. if(!isset($_SERVER['HTTP_CF_RAY'])) $flag = false;
  72. if(!isset($_SERVER['HTTP_CF_VISITOR'])) $flag = false;
  73. return $flag;
  74. }
  75.  
  76. function isCloudflare() {
  77. $ipCheck = _cloudflare_CheckIP($_SERVER['REMOTE_ADDR']);
  78. $requestCheck = _cloudflare_Requests_Check();
  79. return ($ipCheck && $requestCheck);
  80. }
  81.  
  82. function getRequestIP() {
  83. $check = isCloudflare();
  84.  
  85. if($check) {
  86. return $_SERVER['HTTP_CF_CONNECTING_IP'];
  87. } else {
  88. return $_SERVER['REMOTE_ADDR'];
  89. }
  90. }
  91.  
  92.  
  93. ------
  94. $ixp = getRequestIP();
  95.  
  96. call $ixp in webhook
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement