Dynamic address broadcasting


My Linux box gets its address via DHCP, making it sometimes hard for me to find from outside.

I would like it to write its address on a web page whenever it boots up or gets a new address.  Does anyone have a script that does something like this?
Note: I can only use FTP to access the webserver where I want to post the info (ISP's rules).

Who is Participating?
jlevieConnect With a Mentor Commented:
Obligatory caveat: You'd be well advised to check the Terms and Conditions of your service. Some providers take an extremely dim view of their subscribers running web and other servers and have been know to terminate the service when such servers are found.

Okay, on the assumption that you have in mind to mod the pages locally with the correct IP and ship those up to the ISP, I'd definitely do it with a perl script periodically run from cron. As I said, I could write a simple one for you to start with.

What to me would be a better long term solution would be to use one of the dynamic dns services. You'd only have to change the pages one time and could ultimately dispense with the ISP's web server entirely by getting folks used to going directly to your server. One such service (free) is www.dyndns.org and there are free clients that can automatically handle the IP updates.
It would be easy enough to construct a script that could be run from cron or at boot up. I'd think I'd do it from cron, say every half hour, as I don't know how you'd determine if the address had been re-negotiated.

The script would:

1) Get the ip out of an ifconfig.

2) Compare the current IP against a saved copy and if they are different make the new ip become the saved IP and ftp the saved data to the web page using ncftput.

I'd do it with a perl script as it seems to me it'd be easier. I don't have time right now to whip one up, but I'll give it a shot later if someone else doesn't come up with a script in the meantime.

There are places on the Internet that offer this kind of service. Typical costs seem to be in the $20-40 a year and you can have a DNS record associated with the IP. I thought I had a bookmark, but if you do a search on "dynamic dns services" you ought to turn up soemthing.

If you can do cgi-bin on a web server,
you could try something in the line of the following script (untested and I am omitting error checks, etc.):

# your machine ethernet address
ping -q -b -c 5 1> /dev/null 2>&1

SELF=`arp -a | grep $ETH | awk '{print $1}'`

echo 'Content-type: text/plain'
echo ''
echo "You will find yourself as $SELF"

exit 0

The only snag is that the web server this goes on has to be on the same physical segment of your machine (so ping/arp will work, as these days routers tend to drop IP-directed broadcasts. Also, this technique has a (quite low) potential for getting on a netadmin nerves if it gets hit too often.

Actually, I just found out that only root can 'ping -b'. Whoops. Now that's a pity, cause I sorta liked this... So I will post the comment anyway. (I do not think the sysadmin would chmod +s this script...)

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

cubedwellerAuthor Commented:
Maybe it would help if I explain exactly what I am trying to do:

I have a couple hundred megs of web content, but an ISP that only gives me 5 megs of space (RoadRunner).  I figure I can get around this limitation by hosting the vast majority of the site on my Linux box.

I want to make it a seamless user experience, so I hope to write my current IP address into the META http-equiv="refresh" tag on key pages.  This would automatically redirect the user to the right server.

cubedwellerAuthor Commented:
Alright, jlevie, you convinced me.  I went with dyndns.

Thanks again,
Yeah, it just seems like a simpler solution. There are dynamic dns servers that'll service an actual domain name for you (that you'd get registered) rather than the pseudo domain like dyndns uses. I haven't located any free ones though. About $25 or so per year seems to be the norm.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.