#!/usr/bin/env python
import sys
from tftpy import TftpClient as tftp
import os
import time

DEFHOST = "192.168.97.60"
DEFUSER = "admin"
DEFPASS = "domotika"
PORT = 69
HOST = False
USER = False
PASS = False

if (len(sys.argv) > 1 and sys.argv[1] == 'help') or len(sys.argv) == 1:
   print "Usage:\n"
   print "\n"
   print sys.argv[0], "[host] [<username> <password>]"
   print "\n"
   print "if no host is given, it use default one and no username/password."
   print ""
else:
   if len(sys.argv) > 1:
      HOST=sys.argv[1]
      if len(sys.argv) > 3:
         USER = sys.argv[2]
         PASS = sys.argv[3]
      else:
         USER = DEFUSER
         PASS = DEFPASS

   if HOST:
      # Try to reboot the host 
      import urllib
      u=urllib.urlopen('http://'+USER+':'+PASS+'@'+HOST+'/protect/bootload.cgi')
      h=u.read()
      u.close()

      # For the next generation machines
      u=urllib.urlopen('http://'+USER+':'+PASS+'@'+HOST+'/cgi/bootload.cgi')
      h=u.read()
      u.close()

      



