doti3/bar/src/ip_wan.php

58 lines
1.1 KiB
PHP
Executable file

#!/usr/bin/env php
<?php
require __DIR__.'/base/block.php';
$ipv6 = !empty($argv[1]);
$iface = 'wan';
$command = sprintf(
'dig +short %s myip.opendns.com @resolver1.opendns.com 2>/dev/null | grep -v could',
$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 2>/dev/null | grep -v could',
$ipv6 ? '-6' : '-4'
);
$ip = trim(shell_exec($command));
$ip = trim($ip, '"');
}
if (empty($ip)) {
$command = sprintf(
'curl %s ifconfig.co 2>/dev/null',
$ipv6 ? '-6' : '-4'
);
$ip = trim(shell_exec($command));
}
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,
]
);