doti3/bar/src/ip.php
2017-06-19 16:36:59 +02:00

31 lines
540 B
PHP
Executable file

#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$iface = $argv[1] ?? 'eth0';
$inet = ($argv[2] ?? 'inet').' ';
$command = sprintf(
'ip address show %s | grep %s | awk \'{ print $2 }\'',
escapeshellarg($iface),
escapeshellarg($inet)
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
$fullText = sprintf('[%s] %s', $iface, $ip);
$shortText = sprintf('%s: %s', $iface, $ip);
echo block(
'ip_'.$iface.'_'.$inet,
[
'full_text' => $fullText,
'short_text' => $shortText,
]
);