45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Osint\Runners;
|
||
|
|
|
||
|
|
use App\Models\Target;
|
||
|
|
use App\Osint\Runner;
|
||
|
|
use App\Osint\RunnerException;
|
||
|
|
use App\Osint\RunnerResult;
|
||
|
|
use Illuminate\Support\Facades\Http;
|
||
|
|
|
||
|
|
class IpApiRunner implements Runner
|
||
|
|
{
|
||
|
|
public function run(Target $target): RunnerResult
|
||
|
|
{
|
||
|
|
if ($target->type !== 'ip') {
|
||
|
|
throw new RunnerException('ip-api.com only supports "ip" targets.');
|
||
|
|
}
|
||
|
|
|
||
|
|
$response = Http::timeout((int) config('osint.run_timeout'))
|
||
|
|
->get("http://ip-api.com/json/{$target->value}", [
|
||
|
|
'fields' => 'status,message,country,regionName,city,zip,lat,lon,timezone,isp,org,as,query',
|
||
|
|
]);
|
||
|
|
|
||
|
|
if (! $response->successful()) {
|
||
|
|
throw new RunnerException('ip-api.com request failed with status '.$response->status().'.');
|
||
|
|
}
|
||
|
|
|
||
|
|
$data = $response->json();
|
||
|
|
|
||
|
|
if (($data['status'] ?? null) !== 'success') {
|
||
|
|
throw new RunnerException('ip-api.com lookup failed: '.($data['message'] ?? 'unknown error'));
|
||
|
|
}
|
||
|
|
|
||
|
|
$summary = sprintf(
|
||
|
|
'%s, %s, %s (%s)',
|
||
|
|
$data['city'] ?? 'Unknown city',
|
||
|
|
$data['regionName'] ?? 'Unknown region',
|
||
|
|
$data['country'] ?? 'Unknown country',
|
||
|
|
$data['isp'] ?? $data['org'] ?? 'Unknown ISP'
|
||
|
|
);
|
||
|
|
|
||
|
|
return new RunnerResult(raw: $data, summary: $summary);
|
||
|
|
}
|
||
|
|
}
|