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
' find the current dynamic IP address and send a web page to an open server on the internet
' (this is a server that holds your public web server files and which anyone can access)
' the page you upload redirects the user to a menu on a server on the home LAN that has a dynamic web address

' the host on the LAN uses a ramdisk for temporary files - create this within the host boot script using -
' mkdir /var/www/ramdisk
' mount -o size=2M -t tmpfs tmpfs /var/www/ramdisk

' the Linux command ifconfig gets lots of text that includes the dynamic IP address
SHELL "echo -n `ifconfig eth0`>/var/www/ramdisk/eth0.txt"
OPEN "/var/www/ramdisk/eth0.txt" FOR INPUT AS #1 : INPUT #1,eth0_all$ : CLOSE #1

' extract the text that starts with the IP address
ipaddress$ = MID$(eth0_all$,61,25)

' find the character B that follows the address in the string
i=1
LABEL New_i
character$ = MID$(ipaddress$,i,1)
IF character$ = "B" THEN length=i :GOTO NextBit
i=i+1
IF I = 18 THEN GOTO NextBit
GOTO New_i

LABEL NextBit
i=i-2

'extract the IP address (remove the space and the B that follow it)
ipaddress$ = LEFT$(ipaddress$, i)

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
OPEN "/var/www/ramdisk/IP_address.txt" FOR OUTPUT AS #1 : PRINT #1,ipaddress$ : CLOSE #1
SHELL "/root/ncftp_up.sh"

' create the the redirection web page - CHR$34 is "
html_top$ = "<html><head><meta http-equiv="+CHR$34+"refresh"+CHR$34+" content="+CHR$34+"1; URL=http://"

html_bottom$ = CHR$34+"></head><body>jump to menu auto</body></html>"
hop_html$ = html_top$+ipaddress$+html_bottom$

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
OPEN "/var/www/ramdisk/hop.html" FOR OUTPUT AS #1 : PRINT #1,hop_html$ : CLOSE #1
SHELL "/root/ncftp_up-hop_html.sh"
SYSTEM
' from a browser go to http://my_open_server_address/hop.html
' and it will redirect to the menu page on your LAN

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
FTPU="myloginname" # ftp login name
FTPP="mypassword" # ftp password
FTPS="ftp.domain.co.uk" # remote ftp server
FTPF="/www.domain.co.uk/public_html" # remote ftp server directory for $FTPU & $FTPP
LOCALD="/var/www/ramdisk/home_ip.html"

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/

echo "uploading to sunspot"
yafc <<**
open ftp://name:password@my.ftp.server/
ls
cd /www.sunspot.co.uk/foldername/anothersubfolder/uploads
put -f -r /www/ramdisk/home_ip.html
quit

 

(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
openfile = open('/www/ramdisk/home_ip.html', 'r')
openfile.seek(76)
string = openfile.read()
openfile.close()

x = string.find ( '<' )
dottedquad = string[0:x]

f = open('/www/ramdisk/IP-address.txt', 'w')
f.write(dottedquad)
f.close()


 

 

 

 

 

also see http://yafc.sourceforge.net/manual_3.html#SEC8

Comments? email me