Advertisement
Guest User

Untitled

a guest
Sep 8th, 2009
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import urllib
  2.  
  3. import urllib2
  4.  
  5. from lxml import objectify
  6. import sys
  7.  
  8.  
  9. username = "USERNAME"
  10. password = "PASSWORD"
  11. ip_address = "192.168.5.146"
  12.  
  13.  
  14. #yup, here is the password in plain text encoded in the url string, this needs to be cleaned up
  15.  
  16. url = 'http://' + ip_address + '/System.xml?version=1.0&action=login&userName=' + username + '&password=' + password
  17.  
  18. req = urllib2.Request(url)
  19.  
  20. response = urllib2.urlopen(req)
  21.  
  22. page = response.read()
  23.  
  24.  
  25.  
  26. #parse the resulting XML to see if the login worked. lxml might be overkill, but I like it
  27.  
  28. try:
  29.  
  30.     camRespond = objectify.fromstring(page)
  31.  
  32. except Error, e:
  33.  
  34.     print "Error",e
  35.  
  36.  
  37.  
  38. if camRespond.statusCode == 1:
  39.  
  40.     print "Login success"
  41.  
  42.     #the sessionID is returned in in the responding http header
  43.  
  44.     info = response.info()
  45.  
  46.     sessionID = info.get("sessionID")
  47.  
  48.     print "sessionID =", sessionID
  49.  
  50. else:
  51.  
  52.     print "login failed!"
  53.  
  54.     print camRespond
  55.     sys.exit(1)
  56.  
  57.    
  58.  
  59. url = 'http://' + ip_address + '/StreamingSetting.xml?version=1.0&action=get&sessionID=' + sessionID
  60.  
  61. req = urllib2.Request(url)
  62.  
  63. response = urllib2.urlopen(req)
  64.  
  65. page = response.read()
  66.  
  67. print page
  68.  
  69.  
  70.  
  71.  
  72.  
  73. #logout and clean up
  74.  
  75. #url = 'http://' + ip_address + '/System.xml?version=1.0&action=logout&sessionID=' + sessionID
  76.  
  77. #req = urllib2.Request(url)
  78.  
  79. #response = urllib2.urlopen(req)
  80.  
  81. #page = response.read()
  82.  
  83. #print page
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement