IpHelper.php 759 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2020/3/26
  6. * Time: 17:24
  7. */
  8. namespace network;
  9. include EXTEND_PATH . 'network/IpLocation.php';
  10. class IpHelper
  11. {
  12. /**
  13. * 获取某个IP地址所在的位置
  14. * @param $ip
  15. * @return array = ['area'=>area , 'country'=>country]
  16. */
  17. public static function get($ip)
  18. {
  19. $Ips = new IpLocation('UTFWry.dat'); // 实例化类 参数表示IP地址库文件
  20. $area = $Ips->getlocation($ip); // 获取某个IP地址所在的位置
  21. return $area;
  22. }
  23. /**
  24. * @return string
  25. */
  26. public static function getRandIp()
  27. {
  28. return rand(13, 255) . '.' . rand(13, 255) . '.' . rand(13, 255) . '.' . rand(13, 255);
  29. }
  30. }