Browse Source

IP查询更新

兔姬桑 3 years ago
parent
commit
7e96beb8a1
3 changed files with 295 additions and 261 deletions
  1. 28 5
      app/Components/IP.php
  2. 267 256
      composer.lock
  3. BIN
      database/IP2LOCATION-LITE-DB3.IPV6.BIN

+ 28 - 5
app/Components/IP.php

@@ -36,17 +36,17 @@ class IP
     public static function IPSB($ip)
     public static function IPSB($ip)
     {
     {
         try {
         try {
-            $response = Http::withHeaders(['User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'])->timeout(15)->get('https://api.ip.sb/geoip/'.$ip);
+            $response = Http::withHeaders(['User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'])->timeout(15)->post('https://api.ip.sb/geoip/'.$ip);
 
 
             if ($response->ok()) {
             if ($response->ok()) {
                 return $response->json();
                 return $response->json();
             }
             }
 
 
-            Log::warning('api.ip.sb解析'.$ip.'异常: '.$response->body());
+            Log::warning('[IPSB] 解析'.$ip.'异常: '.$response->body());
 
 
             return false;
             return false;
         } catch (Exception $e) {
         } catch (Exception $e) {
-            Log::error('api.ip.sb解析'.$ip.'错误: '.var_export($e->getMessage(), true));
+            Log::error('[IPSB] 解析'.$ip.'错误: '.var_export($e->getMessage(), true));
 
 
             return false;
             return false;
         }
         }
@@ -59,7 +59,7 @@ class IP
         try {
         try {
             $ipInfo = (new Ip2Region())->memorySearch($ip);
             $ipInfo = (new Ip2Region())->memorySearch($ip);
         } catch (Exception $e) {
         } catch (Exception $e) {
-            Log::error('【淘宝IP库】错误信息:'.$e->getMessage());
+            Log::error('【ip2Region】错误信息:'.$e->getMessage());
         }
         }
 
 
         if ($ipInfo) {
         if ($ipInfo) {
@@ -111,11 +111,34 @@ class IP
         ];
         ];
     }
     }
 
 
+    // 通过IPIP在线查询IP地址的详细信息
+    public static function IPIPOnline(string $ip)
+    { // https://freeapi.ipip.net
+        $response = Http::timeout(15)->get('https://freeapi.ipip.net/'.$ip);
+
+        if ($response->ok()) {
+            $message = $response->json();
+            if ($message) {
+                return [
+                    'country'  => $message[0],
+                    'province' => $message[1],
+                    'city'     => $message[2],
+                ];
+            }
+
+            Log::warning('【IPIP在线】返回错误信息:'.$ip.PHP_EOL.$message['msg']);
+        } else {
+            Log::error('【IPIP在线】解析异常:'.$ip);
+        }
+
+        return false;
+    }
+
     // 通过ip.taobao.com查询IP地址的详细信息
     // 通过ip.taobao.com查询IP地址的详细信息
     public static function TaoBao(string $ip)
     public static function TaoBao(string $ip)
     {
     {
         // 依据 https://ip.taobao.com/instructions 开发
         // 依据 https://ip.taobao.com/instructions 开发
-        $response = Http::timeout(15)->get('https://ip.taobao.com/outGetIpInfo?ip='.$ip.'&accessKey=alibaba-inc');
+        $response = Http::timeout(15)->post('https://ip.taobao.com/outGetIpInfo?ip='.$ip.'&accessKey=alibaba-inc');
 
 
         if ($response->ok()) {
         if ($response->ok()) {
             $message = $response->json();
             $message = $response->json();

File diff suppressed because it is too large
+ 267 - 256
composer.lock


BIN
database/IP2LOCATION-LITE-DB3.IPV6.BIN


Some files were not shown because too many files changed in this diff