Until recently, I’d been using WhatIsMyIP.com’s API to fill in the external IP field in my Conky readout, but a few days ago, they started a very silly thing where, for whatever reason, clients have to follow a 301 redirect to the URL they just asked for in order to get the IP. I decided that was excuse enough to write a more direct solution.
Since, recently, I’d learned that it’s possible to muck about in m0n0wall without pulling the CF card (despite the lack of proper SSH), I decided to take m0n0wall’s interfaces readout page, strip out everything that wasn’t necessary to get the WAN IPv4 address, and add an explode() call to separate the IP from the hostmask.
If you want it for your own m0n0wall box, here are the instructions:
api_wan_ipaddr4.phpfrom my GitHub Gist.
- Go to exec.php on your m0n0wall box (http://192.168.1.1/exec.php with the default DHCP configuration)
- (optional) Type “
status_interfaces.php” into the download box and use a tool like diff to verify that I haven’t added anything nefarious.
- Use the exec.php upload interface to upload
- Run these commands using the exec field:
mv /tmp/api_wan_ipaddr4.php /usr/local/www chmod 755 api_wan_ipaddr4.php
- Load it in your browser (http://192.168.1.1/api_wan_ipaddr4.php with defaults) to confirm that it’s working.
- Use wget/curl/etc. with HTTP authentication to retrieve your external IP whenever you want. I use this command for my conky:
curl -s --insecure --anyauth --netrc https://192.168.0.1/api_wan_ipaddr4.php