I've seen a program called Devcon (http://en.kioskea.net/faq/sujet-1886-enable-disable-a-device-from-the-command-line) used for enabling and disabling hardware devices. I want to do the same hopefully with python.

I want to turn the internet connection off with a script. I can already do it with popen('ipconfig /release') but I want something more robust. Is there any modules or library's that allow me access to devices, or will I have to stick with popen()?

Its for my uncle. He wants to kick his daughter off-line so she can do her homework instead of wasting her life on myspace and facebook.

Recommended Answers

All 3 Replies

so does he want the thing to be able to turn things off from another computer?

Two module comes in mind.

Python Win32 Extensions.
http://python.net/crew/skippy/win32/Downloads.html
Tim Golden's excellent WMI.
http://tgolden.sc.sabren.com/python/wmi/index.html

WMI has an excellent way of looking at many hardware settings,
but has limited support for changing many of them.

Try pypi to see if someone has make somthing for this.
http://pypi.python.org/pypi

Maybe better to find a network soultion(something like you have now)
So low level as disabling hardware devices can be a problem,but very few thing are impossible.

I found WMI which does exactly what I need it to.
I convert the time to decimal form so i can copare numbers instead of strings. The "target" is in Virginia, and the website I found didn'y have Virginia, so I use Miami's time instead. Time.gov's site updates the times on the tables instead of using java to fill the tables from a database.

It is used to kick my kid cousin offline between given hours, because she wastes her time on facebook and myspace instead of doing her homework.

#http://www.time.gov/timezone.cgi?Eastern/d/-5/java
#Version 2
#Uses WMI to kill Mozzilla FireFox and Internet Exploder intead #releasing the ip adress


import urllib2, time, sys, string, locale, wmi

def cnvtime(t):
  tr = string.replace(t,':','.')
  ts = tr.split()
  ti = ts[0]
  M = ts[1]
  tf = locale.atof(ti)
  return tf, M


while 1:
  response = urllib2.urlopen('http://www.timeanddate.com/worldclock/custom.html?sort=1')
  #time.sleep(5)
  html = response.read() 
  ri = html.index('Miami')#The site didn't have Virginia, so Miami is used.
  t = html[ri+4:ri+39]
  timeDate = t[28:]
  timeDate = cnvtime(timeDate)
  print timeDate
  if timeDate[0] >= 2.34 and timeDate[0] <= 2.36 and timeDate[1] == 'PM':
    for i in wmi.WMI().Win32_Process(Name="iexplore.exe"):
      i.Terminate()
    for m in wmi.WMI().Win32_Process(Name="firefox.exe"):
      m.Terminate()

  time.sleep(10)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.