Sunspot Home
Objective
See my home webcams when I am away even though
I do not have a static IP address on my home LAN
I tried a free DNS server but they switched off my account. . . . . . .
Method
Use a Linux server on the home LAN to find the current IP address using ifconfig.
Use Blassic basic to extract the IP address as a string and create a webpage for the server.
Upload the webpage (including the current IP address) to the public server using ncftp
The webpage on the public server automatically redirects the user after 1 second to
a menu webpage on the home LAN
The Blassic program
#!/usr/sbin/blassic ' the host on the LAN uses a ramdisk for temporary files - create this within the host boot script using - ' the Linux command ifconfig gets lots of text that includes the dynamic IP address ' extract the text that starts with the IP address ' find the character B that follows the address in the string LABEL NextBit 'extract the IP address (remove the space and the B that follow it) PRINT ipaddress$ ' pass the IP address to bash and ask ncftp to send it to the open server on the internet as a text file ' create the the redirection web page - CHR$34 is " html_bottom$ = CHR$34+"></head><body>jump to menu auto</body></html>" PRINT hop_html$ ' pass the redirection web page to bash and ask ncftp to send it to the open server on the internet as html |
the web page is like this
<html><head><meta http-equiv="refresh" content="1; URL=http:// 123.123.123.123 "></head><body>jump to menu</body></html> |
ncftp is used like this -
#/bin/bash FTPU="myname" # ftp login name FTPP="mypassword" # ftp password FTPS="ftp.myftpserver.co.uk" # remote ftp server FTPF="/www.mydomain.co.uk/public_html" # remote ftp server directory for $FTPU & $FTPP LOCALD="/var/www/ramdisk/filetosend.txt" ncftpput -m -u $FTPU -p $FTPP $FTPS $FTPF $LOCALD |
Just shows how little about code writing you actually need to know when you have Blassic and Google!
A simple way to show the local home IP address on a public server
thanks to http ://checkip.dyndns.org/
#/bin/bash wget -O $LOCALD http://checkip.dyndns.org/ ncftpput -m -u $FTPU -p $FTPP $FTPS $FTPF $LOCALD |
Thanks to Google and charvi
Doing the same for OpenWrt on nslu2
I was not able to find an opkg for ncftpput but yafc was available ("yet another ftp client")
this small script let me log on to my main server and upload a file called yafc-dns.sh
#!/bin/sh wget -O /www/ramdisk/home_ip.html http://checkip.dyndns.org/ |
(It took some searching to find a way of scripting this - you could run yafc but then you ended up with a yafc prompt and no way to enter the put upload line.
The <<** seems to be the magic but it is not documented in the yafc man pages)
/etc/cron/root contains
# upload the IP address to sunspot every 20 minutes
*/20 * * * * /path-to/yafc-dns.sh
(if using "crontab -e" you are in vi (!) - to save do esc :wq to save the changes)
This python program runs in minipython on the openwrt slug when called by the bash script yafc-dns.sh (above)
which wgets the current IP address from
http://checkip.dyndns.org/ and stores all of that webpage in the ramdisk.
openfile.seek(76) forms a string starting at character 76 of the html from the saved web page
the string.find makes x equal to the number along the string where the character < is found
This finds the end of the IP address which may be shorter than 4 quads of numbers
#!/usr/bin/python x = string.find ( '<' ) f = open('/www/ramdisk/IP-address.txt', 'w') |
also see http://yafc.sourceforge.net/manual_3.html#SEC8
Comments? email me