doti3/bar/src/ip_wan.php

58 lines
1.1 KiB
PHP
Raw Normal View History

2021-03-03 21:31:06 +01:00
#!/usr/bin/env php
2017-06-19 16:36:59 +02:00
<?php
require __DIR__.'/base/block.php';
$ipv6 = !empty($argv[1]);
2020-01-14 11:35:27 +01:00
2017-06-19 16:36:59 +02:00
$iface = 'wan';
$command = sprintf(
'dig +short %s myip.opendns.com @resolver1.opendns.com 2>/dev/null | grep -v could',
2017-06-19 16:36:59 +02:00
$ipv6 ? '-6' : null
);
$ip = trim(shell_exec($command));
2020-01-14 11:35:27 +01:00
if (empty($ip)) {
$command = sprintf(
'dig +short %s TXT o-o.myaddr.l.google.com @ns1.google.com 2>/dev/null | grep -v could',
2020-01-14 11:35:27 +01:00
$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));
}
2017-06-19 16:36:59 +02:00
if (empty($ip)) {
die;
}
2018-01-03 13:53:49 +01:00
if (getenv('BLOCK_BUTTON') === '1') {
2020-01-14 11:35:27 +01:00
shell_exec('
export DISPLAY=:0
printf '.escapeshellarg($ip).' | xclip -sel clip
notify-send "Valeur copiée" '.escapeshellarg($ip).'
');
2018-01-03 13:53:49 +01:00
}
2019-01-28 11:13:11 +01:00
$fullText = pspan($iface, '#ccc', '#222').pspan($ip, '#ddd', '#000');
2017-06-19 16:36:59 +02:00
echo block(
2017-12-04 19:41:16 +01:00
'ip_wan',
2017-06-19 16:36:59 +02:00
[
'full_text' => $fullText,
2019-01-21 16:20:04 +01:00
'separator' => false,
'separator_block_width' => 0,
2017-06-19 16:36:59 +02:00
]
);