Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions app/Commands/Network/LanScanCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace App\Commands\Network;

use App\Commands\Concerns\InteractsWithLocale;
use App\Contracts\SystemDriverInterface;
use LaravelZero\Framework\Commands\Command;

use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;
use function Laravel\Prompts\table;
use function Laravel\Prompts\warning;

class LanScanCommand extends Command
{
use InteractsWithLocale;

/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'network:scan {--lang= : Interface language (en or pt_BR)}';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Discover active devices on the local area network (ARP cache & neighbor table)';

/**
* Execute the console command.
*/
public function handle(SystemDriverInterface $driver): int
{
$this->resolveLocale();

info((string) __('messages.network.scan_section'));

/** @var array<int, array{ip: string, mac: string, status: string, interface: string}> $devices */
$devices = spin(
callback: fn (): array => $driver->scanLanDevices(),
message: (string) __('messages.spinners.network_scan'),
);

if ($devices === []) {
warning((string) __('messages.network.no_lan_devices'));

return self::SUCCESS;
}

table(
headers: [
(string) __('messages.network.scan_headers.ip'),
(string) __('messages.network.scan_headers.mac'),
(string) __('messages.network.scan_headers.status'),
(string) __('messages.network.scan_headers.interface'),
],
rows: array_map(
fn (array $device): array => [
$device['ip'] ?? '-',
$device['mac'] ?? '-',
$device['status'] ?? '-',
$device['interface'] ?? '-',
],
$devices
),
);

return self::SUCCESS;
}
}
63 changes: 63 additions & 0 deletions app/Commands/Network/NetResetCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace App\Commands\Network;

use App\Commands\Concerns\InteractsWithLocale;
use App\Contracts\SystemDriverInterface;
use LaravelZero\Framework\Commands\Command;

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;
use function Laravel\Prompts\warning;

class NetResetCommand extends Command
{
use InteractsWithLocale;

/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'network:reset
{--force : Skip confirmation prompt}
{--lang= : Interface language (en or pt_BR)}';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Perform a full network stack reset (Winsock/IP reset on Windows; NetworkManager/DHCP on Linux)';

/**
* Execute the console command.
*/
public function handle(SystemDriverInterface $driver): int
{
$this->resolveLocale();

info((string) __('messages.network.reset_section'));

if (! $this->option('force') && ! confirm(
label: (string) __('messages.network.confirm_reset'),
default: false,
yes: (string) __('messages.common.yes'),
no: (string) __('messages.common.no'),
)) {
warning((string) __('messages.common.cancelled'));

return self::SUCCESS;
}

$result = spin(
callback: fn () => $driver->resetNetworkStack(),
message: (string) __('messages.spinners.network_reset'),
);

return $this->renderActionResult($result);
}
}
114 changes: 114 additions & 0 deletions app/Commands/Network/ProbeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

declare(strict_types=1);

namespace App\Commands\Network;

use App\Commands\Concerns\InteractsWithLocale;
use App\Contracts\SystemDriverInterface;
use LaravelZero\Framework\Commands\Command;

use function Laravel\Prompts\error;
use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;
use function Laravel\Prompts\table;
use function Laravel\Prompts\text;

class ProbeCommand extends Command
{
use InteractsWithLocale;

/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'network:probe
{host? : Target hostname or IP address}
{port? : Target TCP port number (1-65535)}
{--timeout=3 : Connection timeout in seconds}
{--lang= : Interface language (en or pt_BR)}';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Test a remote TCP host and port connection and measure response latency';

/**
* Execute the console command.
*/
public function handle(SystemDriverInterface $driver): int
{
$this->resolveLocale();

info((string) __('messages.network.probe_section'));

$hostArg = $this->argument('host');
$host = is_string($hostArg) && trim($hostArg) !== ''
? trim($hostArg)
: text(
label: (string) __('messages.network.probe_host_prompt'),
default: '1.1.1.1',
required: true,
);

$portArg = $this->argument('port');
$portStr = is_string($portArg) && trim($portArg) !== ''
? trim($portArg)
: text(
label: (string) __('messages.network.probe_port_prompt'),
default: '443',
required: true,
validate: fn (string $val): ?string => (is_numeric($val) && (int) $val >= 1 && (int) $val <= 65535)
? null
: (string) __('messages.network.probe_invalid_port'),
);

$port = max(1, min(65535, (int) $portStr));
$timeout = max(1, (int) $this->option('timeout'));

$result = spin(
callback: fn (): array => $driver->probePort($host, $port, $timeout),
message: (string) __('messages.spinners.network_probe', ['host' => $host, 'port' => $port]),
);

table(
headers: [
(string) __('messages.network.probe_headers.host'),
(string) __('messages.network.probe_headers.port'),
(string) __('messages.network.probe_headers.status'),
(string) __('messages.network.probe_headers.latency'),
(string) __('messages.network.probe_headers.details'),
],
rows: [
[
$result['host'],
(string) $result['port'],
$result['status'],
$result['latency'],
$result['error'],
],
],
);

if ($result['status'] === 'OPEN') {
info((string) __('messages.network.probe_open_success', [
'host' => $result['host'],
'port' => $result['port'],
'latency' => $result['latency'],
]));

return self::SUCCESS;
}

error((string) __('messages.network.probe_failed', [
'host' => $result['host'],
'port' => $result['port'],
'status' => $result['status'],
]));

return self::FAILURE;
}
}
48 changes: 48 additions & 0 deletions app/Commands/Network/PublicIpCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace App\Commands\Network;

use App\Commands\Concerns\InteractsWithLocale;
use App\Contracts\SystemDriverInterface;
use LaravelZero\Framework\Commands\Command;

use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;

class PublicIpCommand extends Command
{
use InteractsWithLocale;

/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'network:public {--lang= : Interface language (en or pt_BR)}';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Retrieve external public IP address, geolocation, ISP/ASN, and reverse hostname';

/**
* Execute the console command.
*/
public function handle(SystemDriverInterface $driver): int
{
$this->resolveLocale();

info((string) __('messages.network.public_section'));

$result = spin(
callback: fn () => $driver->getPublicIpInfo(),
message: (string) __('messages.spinners.network_public'),
);

return $this->renderActionResult($result);
}
}
63 changes: 63 additions & 0 deletions app/Commands/Network/SslCheckCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace App\Commands\Network;

use App\Commands\Concerns\InteractsWithLocale;
use App\Contracts\SystemDriverInterface;
use LaravelZero\Framework\Commands\Command;

use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;
use function Laravel\Prompts\text;

class SslCheckCommand extends Command
{
use InteractsWithLocale;

/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'network:ssl
{domain? : Target HTTPS domain name}
{--port=443 : Target HTTPS TCP port}
{--lang= : Interface language (en or pt_BR)}';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Inspect an HTTPS domain SSL/TLS certificate (Subject, Issuer, Expiration, Days Remaining, SANs)';

/**
* Execute the console command.
*/
public function handle(SystemDriverInterface $driver): int
{
$this->resolveLocale();

info((string) __('messages.network.ssl_section'));

$domainArg = $this->argument('domain');
$domain = is_string($domainArg) && trim($domainArg) !== ''
? trim($domainArg)
: text(
label: (string) __('messages.network.ssl_domain_prompt'),
default: 'google.com',
required: true,
);

$port = max(1, min(65535, (int) $this->option('port')));

$result = spin(
callback: fn () => $driver->checkSslCertificate($domain, $port),
message: (string) __('messages.spinners.network_ssl', ['domain' => $domain]),
);

return $this->renderActionResult($result);
}
}
Loading
Loading