当前位置:   article > 正文

判断国内ip

判断国内ip

php代码

  1. //是否国内ip
  2. function isChinaIP($ip) {
  3. saveLog("---isChinaIP----------");
  4. $url = "https://searchplugin.csdn.net/api/v1/ip/get?ip=".$ip;
  5. // 发送HTTP请求
  6. $response = file_get_contents($url);
  7. $utf8String = mb_convert_encoding($response, "UTF-8", "auto");
  8. saveLog("--isChinaIP---".$utf8String);
  9. // 解析JSON响应
  10. $data = json_decode($utf8String, true);
  11. // 判断所属地区是否为中国
  12. saveLog("isChinaIP address ".$data['data']['address']);
  13. if ($data && isset($data['data']['address']) && (strpos($data['data']['address'],"中国")!==false) ) {
  14. saveLog("isChinaIP true");
  15. return true;
  16. } else {
  17. return false;
  18. }
  19. }

返回值

{"code":200,"msg":"success","data":{"address":"中国 重庆 重庆 电信","ip":"183.69.129.158"}}'

参考:https://blog.csdn.net/m0_53025912/article/details/132258243

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/786588
推荐阅读
相关标签
  

闽ICP备14008679号