Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib
- import urllib2
- from lxml import objectify
- import sys
- username = "USERNAME"
- password = "PASSWORD"
- ip_address = "192.168.5.146"
- #yup, here is the password in plain text encoded in the url string, this needs to be cleaned up
- url = 'http://' + ip_address + '/System.xml?version=1.0&action=login&userName=' + username + '&password=' + password
- req = urllib2.Request(url)
- response = urllib2.urlopen(req)
- page = response.read()
- #parse the resulting XML to see if the login worked. lxml might be overkill, but I like it
- try:
- camRespond = objectify.fromstring(page)
- except Error, e:
- print "Error",e
- if camRespond.statusCode == 1:
- print "Login success"
- #the sessionID is returned in in the responding http header
- info = response.info()
- sessionID = info.get("sessionID")
- print "sessionID =", sessionID
- else:
- print "login failed!"
- print camRespond
- sys.exit(1)
- url = 'http://' + ip_address + '/StreamingSetting.xml?version=1.0&action=get&sessionID=' + sessionID
- req = urllib2.Request(url)
- response = urllib2.urlopen(req)
- page = response.read()
- print page
- #logout and clean up
- #url = 'http://' + ip_address + '/System.xml?version=1.0&action=logout&sessionID=' + sessionID
- #req = urllib2.Request(url)
- #response = urllib2.urlopen(req)
- #page = response.read()
- #print page
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement