VZ installed a d-link DI-604 “Broadband router” in between my home network and the ONT on the side of the house. The d-link’s job is setting up the PPPoE connection back to Verizon, NAT, and firewalling. Verizon uses dynamic IP addressing for public IP addresses, and rumour has it that they reassign IP addresses frequently - but the d-link hides these changes.
(Apparently there are some specialized diagnostic tests the d-link knows how to run as well. It appears to be running a custom firmware load, with a version number that doesn’t appear on d-link’s support site. And when I tried to upgrade its firmware, the d-link rejected the new version.)
I want to know my public IP address so I can access my home computer from work or other places. (I use zoneedit.com to maintain an Internet-visible domain name.) The d-link makes this hard! I have used ddclient for this job in the past - basically it connects to the embedded web server on the d-link (or similar devices), and scrapes the IP address out of the web pages. (We used to use this kludge to interface then-modern computers to IBM mainframes - I guess old kludges never die.)
Unfortunately, ddclient only understands “basic” HTML authentication, and the d-link wants “digest” authentication. (Basic is pretty insecure, and Digest uses MD5 hashes which are much better. But all of this is already hidden behind the d-link’s own firewall, so who cares?) In fact, d-link is very picky about its digest authentication - it would talk to firefox and curl, but not lynx, links, or wget, all of which support digest authentication.
So here’s the snippet that works - for a while:
curl -f -s --digest --connect-timeout 10 --interface eth0 -u admin:password http://192.168.0.1/st_devic.html |
egrep '^[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]‘ |
head -n 3 | tail -n 1 | tr -d ‘[:space:]‘
But see the next entry.