Skip to content

Instantly share code, notes, and snippets.

@pauladam
Created November 4, 2009 22:59
Show Gist options
  • Save pauladam/226467 to your computer and use it in GitHub Desktop.
Save pauladam/226467 to your computer and use it in GitHub Desktop.
Simple script for remotely shutting down your DS nas device. Im lazy so I like to avoid logging into the web ui and clicking around.
#!/usr/bin/python
import urllib,urllib2, sys
BASE_URL = 'http://192.168.100.101:5000'
ADMIN_PASS = 'YOUR ADMIN PASS'
# Login to admin interface
parameters = {'username' : 'admin', 'passwd':ADMIN_PASS,'service_type':'1'}
request = urllib2.Request(BASE_URL+'/webman/modules/login.cgi', urllib.urlencode(parameters))
response = urllib2.urlopen(request)
resp = response.read()
set_cookie = response.headers.getheader("Set-Cookie")
sess_id = set_cookie[set_cookie.index("=")+1:set_cookie.index(";")]
headers = {"Cookie": "id="+sess_id}
if 'success' in resp:
print 'Logged in successfully...'
# Reboot or shutdown the device
# 'reboot' is also a valid command
parameters = {'opt' : 'shutdown'}
request = urllib2.Request(BASE_URL+'/webman/modules/reboot.cgi', urllib.urlencode(parameters), headers=headers)
response = urllib2.urlopen(request)
resp = response.read()
if 'success' in resp:
print 'Powering down...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment