SMS + libgmail + cron = All sorts of fun

Part 2 - What Is My IP?

The harness script for part one was overkill, but I had bigger plans. The cronjob is the same except that really I call a script that runs several scripts. Like this one.


import libgmail
import commands
import subprocess

if __name__ == "__main__":

    out = libgmail.GmailAccount("junkygmail", "junkypassword")    

Should a message turn up in my account with the subject line "Ip?":

    if out.getUnreadMsgCount():
        folder = out.getUnreadMessages()
        for thread in folder:
            for msg in thread:
		if msg.subject == "Ip?":

Drop the firewall. There is no nice way to do this with my hardware, I recorded the steps of web configuration using Lynx. -cmd_script runs the key presses recorded by -cmd_log

          ["lynx http://ROUTERIP/network
                      -cmd_script=~/bin/drop_firewall"], shell=True)

Here is the fun bit; there is also no nice way to find your IP. You have to ask another computer outside the network. I ask (well, use lynx to scrape it off) my router:

				    "IP: " + 
			    "lynx http://ROUTERIP/firewall_details.html -dump 
			      | grep SSH | awk'{print $7}'")))

The grep and awk depend upon how the router web configuration is laid out, but at least it is firmware and not subject to change.

Yay! I'm better than chuffed. Now when I'm offsite working with a client and need to access my computer, I can just send it a txt and it'll send me back it's IP so I can SSH in.

Also, Lynx is awesome.

April 20, 2009