Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import httplib
  2.  
  3. import base64
  4.  
  5. import StringIO
  6.  
  7.  
  8.  
  9. class Trendnet():
  10.  
  11.  
  12.  
  13. def __init__(self, ip='1.1.1.1', username='admin', password='admin'):
  14.  
  15. self.IP = ip
  16.  
  17. self.Username = username
  18.  
  19. self.Password = password
  20.  
  21. self.Connected = False
  22.  
  23.  
  24.  
  25. def Connect(self):
  26.  
  27. print 'Attempting to connect to camera...'
  28.  
  29. try:
  30.  
  31. h = httplib.HTTP(self.IP)
  32.  
  33. h.putrequest('GET','/cgi/mjpg/mjpeg.cgi')
  34.  
  35. h.putheader('Authorization', 'Basic %s' % base64.encodestring('%s:%s' % (username, password))[:-1])
  36.  
  37. h.endheaders()
  38.  
  39. errcode, errmsg, headers = h.getreply()
  40.  
  41. self.file = h.getfile()
  42.  
  43. self.Connected = True
  44.  
  45. print 'Connected!'
  46.  
  47. return True
  48.  
  49. except:
  50.  
  51. print 'Unable to Connect'
  52.  
  53. self.Connected = False
  54.  
  55. return False
  56.  
  57.  
  58.  
  59. def Update(self):
  60.  
  61. if self.Connected:
  62.  
  63. s = self.File.readline() # '--myboundry'
  64.  
  65. s = self.File.readline() # 'Content-Length: #####'
  66.  
  67. framesize = int(s[16:])
  68.  
  69. s = self.File.read(framesize) # jpeg data
  70.  
  71. while s[0] != chr(0xff): # strip off some junk in front of the jpeg
  72.  
  73. s = s[1:]
  74.  
  75. return StringIO.StringIO(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement