#!/usr/bin/php
<?php

require __DIR__.'/base/block.php';

$ipv6 = !empty($argv[1]);

$iface = 'wan';

$command = sprintf(
    'dig +short myip.opendns.com @resolver1.opendns.com',
    $ipv6 ? '-6' : null
);

$ip = trim(shell_exec($command));

if (empty($ip)) {
    die;
}

if (getenv('BLOCK_BUTTON') === '1') {
    shell_exec('export DISPLAY=:0; printf '.escapeshellarg($ip).' | xclip');
    shell_exec('export DISPLAY=:0; printf '.escapeshellarg($ip).' | xclip -sel clip');
}

$fullText = pspan($iface, '#ccc', '#222').pspan($ip, '#ddd', '#000');

echo block(
    'ip_wan',
    [
        'full_text' => $fullText,
        'separator' => false,
        'separator_block_width' => 0,
    ]
);
Embed
<div%key%id="gist-5c87a2474b9eb-09e8dcb811bffb18759359085e70013cdc567cb3" class="gist-container"></div>
<script src="https://gist.deblan.org/en/embedjs/5c87a2474b9eb" async></script>