IP地址查询(通过百度接口分析得出)

2021-07-19 03:08:45   工作备份

 

  1. /**
  2. * 百度ip地址查询接口
  3. * @param $ip
  4. * @return mixed
  5. */
  6. function ipBaiduSearch($ip){
  7. //初始化
  8. $curl = curl_init ( ) ;
  9. $params = [
  10. 'query'=>$ip, 'resource_id'=>5809, 't'=>microtime(), 'ie'=>'utf8', 'format'=>'json', 'tn'=>'baidu'
  11. ];
  12. //设置抓取的url
  13. curl_setopt ( $curl , CURLOPT_URL , 'https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?'.http_build_query($params) ) ;
  14. //设置头文件的信息作为数据流输出
  15. curl_setopt ( $curl , CURLOPT_HEADER , 0 ) ;
  16. curl_setopt($curl, CURLOPT_TIMEOUT, 3);
  17. //设置获取的信息以文件流的形式返回,而不是直接输出。
  18. curl_setopt ( $curl , CURLOPT_RETURNTRANSFER , 1 ) ;
  19. //执行命令
  20. $data = curl_exec ( $curl ) ;
  21. //关闭URL请求
  22. curl_close ( $curl ) ;
  23. //显示获得的数据
  24. return json_decode($data,true)['data'][0]??[];
  25. }
  1. ###返回结果
  2. {
  3. "srcid": "5809",
  4. "resourceid": "5809",
  5. "OriginQuery": "127.0.0.1",
  6. "origipquery": "127.0.0.1",
  7. "query": "127.0.0.1",
  8. "origip": "127.0.0.1",
  9. "location": "保留地址 ",
  10. "userip": "",
  11. "showlamp": "1",
  12. "tplt": "ip",
  13. "titlecont": "IP地址查询",
  14. "realurl": "http://www.ip138.com/",
  15. "showLikeShare": "1",
  16. "shareImage": "1"
  17. }