doti3/bar/src/ip_wan.php
2020-01-14 11:35:27 +01:00

49 lines
914 B
PHP
Executable file

#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$ipv6 = !empty($argv[1]);
$iface = 'wan';
$command = sprintf(
'dig +short %s myip.opendns.com @resolver1.opendns.com',
$ipv6 ? '-6' : null
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
$command = sprintf(
'dig +short %s TXT o-o.myaddr.l.google.com @ns1.google.com',
$ipv6 ? '-6' : '-4'
);
$ip = trim(shell_exec($command));
$ip = trim($ip, '"');
}
if (empty($ip)) {
die;
}
if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('
export DISPLAY=:0
printf '.escapeshellarg($ip).' | xclip -sel clip
notify-send "Valeur copiée" '.escapeshellarg($ip).'
');
}
$fullText = pspan($iface, '#ccc', '#222').pspan($ip, '#ddd', '#000');
echo block(
'ip_wan',
[
'full_text' => $fullText,
'separator' => false,
'separator_block_width' => 0,
]
);