doti3/bar/src/ip_wan.php

30 lines
501 B
PHP
Raw Normal View History

2017-06-19 16:36:59 +02:00
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$ipv6 = !empty($argv[1]);
$iface = 'wan';
$command = sprintf(
'wget -O - -q %s "https://api.ipify.org/?format=text" | head -n 1 | cut -c1-50',
$ipv6 ? '-6' : null
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
$fullText = sprintf('[%s] %s', $iface, $ip);
$shortText = sprintf('%s: %s', $iface, $ip);
echo block(
2017-12-04 19:41:16 +01:00
'ip_wan',
2017-06-19 16:36:59 +02:00
[
'full_text' => $fullText,
'short_text' => $shortText,
]
);