42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace app\controller;
|
||
|
use support\Request;
|
||
|
use Webman\Captcha\CaptchaBuilder;
|
||
|
use support\View;
|
||
|
use Respect\Validation\Validator as v;
|
||
|
use support\Redis;
|
||
|
use GeoIp2\Database\Reader;
|
||
|
|
||
|
|
||
|
class api
|
||
|
{
|
||
|
public function search(Request $request)
|
||
|
{
|
||
|
$content=$request->input('content','0');
|
||
|
$contenttype=v::ip()->validate($content);
|
||
|
if(!$contenttype){
|
||
|
$contenttype=v::domain(false)->validate($content);
|
||
|
if(!$contenttype){
|
||
|
return '请输入合法的IP或域名';
|
||
|
}else{
|
||
|
$contenttype='domain';
|
||
|
}
|
||
|
}else{
|
||
|
$contenttype='ip';
|
||
|
$msg['host']=gethostbyaddr("$content");
|
||
|
$reader = new Reader(base_path().'/geoip/GeoLite2-City/GeoLite2-City.mmdb');
|
||
|
$locate=$reader->city($content);
|
||
|
$msg['location']=$locate->raw['country']['names']['zh-CN'].'--'.$locate->raw['city']['names']['zh-CN'];
|
||
|
$msg['Network']=$locate->traits->record['network'];
|
||
|
$asnreader= new Reader(base_path().'/geoip/GeoLite2-ASN/GeoLite2-ASN.mmdb');
|
||
|
$asnreader=$asnreader->Asn("$content");
|
||
|
$msg['ASN']="<a href='//whois.ipip.net/AS".$asnreader->autonomousSystemNumber." ' target='_ipip'>AS:"$asnreader->autonomousSystemNumber.'/'.$asnreader->autonomousSystemOrganization.'</a>';
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
return d($msg);
|
||
|
}
|
||
|
|
||
|
}
|