Advertisement
Guest User

Untitled

a guest
Oct 6th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. import os
  2. import urllib2
  3.  
  4. #Last address in address_list should be +1, to cover all needed diapasone
  5.  
  6. #Variables define begins
  7. address_list = ["192.168.1.%d"%x for x in range(101,104)]
  8. address_list2 = ["192.168.1.%d"%x for x in range(101,104)]
  9. login = 'admin'
  10. password = 'admin'
  11. login2 = 'user'
  12. password2 = ['user0',
  13. 'user1',
  14. 'user2']
  15. name = ['TM_TMN_00',
  16. 'TM_TMN_01',
  17. 'TM_TMN_02']
  18. GW = '192.168.1.1'
  19. SM = '255.255.255.0'
  20. ip_count = 0
  21. #Variables define ends
  22.  
  23.  
  24. for address, address2 in zip(address_list, address_list2):
  25. print "______________________________"
  26. print address, address2
  27. print "Working with ", address
  28. f = urllib2.urlopen('http://%s/'%address)
  29. #print f.read(100)
  30.  
  31. #Authorization begins
  32. auth_handler = urllib2.HTTPBasicAuthHandler()
  33. auth_handler.add_password(realm='Device_CGI',
  34. uri='http://%s'%address,
  35. user=login,
  36. passwd=password)
  37. opener = urllib2.build_opener(auth_handler)
  38. urllib2.install_opener(opener)
  39. print "Authorization at", address, "is OK"
  40. #Authorization ends
  41.  
  42. #Add new user begins
  43. print ""
  44. print "Setting up new login/pass at", address
  45. s = 'http://' + address + '/cgi-bin/userManager.cgi?action=addUser&user.Name=' + login2 + '&user.Password=' + password2[ip_count] + '&user.Group=admin&user.Sharable=true&user.Reserved=false&user.AuthList=CtrlPanel,ShutDown,Record,Backup'
  46. print "New password set is", password2[ip_count]
  47. print s
  48. p = urllib2.urlopen(s)
  49. text = p.read()
  50. print text.splitlines()
  51. #Add new user ends
  52.  
  53. #Setting up encoder begins
  54. print ""
  55. print "Setting up encoder settings at", address
  56. v = 'http://' + address + '/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Video.BitRate=2048&Encode[0].MainFormat[0].Video.Width=1280&Encode[0].MainFormat[0].Video.Height=720&Encode[0].MainFormat[0].Video.FPS=25&Encode[0].MainFormat[0].Video.GOP=50&Encode[0].ExtraFormat[0].VideoEnable=false&Encode[0].MainFormat[0].AudioEnable=false'
  57. print v
  58. p = urllib2.urlopen(v)
  59. text = p.read()
  60. print text.splitlines()
  61. # Setting up encoder ends
  62.  
  63. # Setting up OSD begins
  64. print ""
  65. print "Setting up OSD settings at", address
  66. o = 'http://' + address + '/cgi-bin/configManager.cgi?action=setConfig&ChannelTitle[0].Name=' + name[ip_count] + '&VideoWidget[0].TimeTitle.ShowWeek=true'
  67. print o
  68. p = urllib2.urlopen(o)
  69. text = p.read()
  70. print text.splitlines()
  71. # Setting up OSD ends
  72.  
  73. # Setting up NTP begins
  74. print ""
  75. print "Setting up NTP settings at", address
  76. q = 'http://' + address + '/cgi-bin/configManager.cgi?action=setConfig&NTP.Address=10.6.36.49&NTP.Enable=true&NTP.TimeZone=7'
  77. print q
  78. p = urllib2.urlopen(o)
  79. text = p.read()
  80. print text.splitlines()
  81. # Setting up NTP ends
  82.  
  83. # Setting up IP begins
  84. print ""
  85. print "Setting up IP settings at", address
  86. w = 'http://' + address + '/cgi-bin/configManager.cgi?action=setConfig&Network.eth0.DefaultGateway=' + GW + '&Network.eth0.IPAddress=' + address2 + '&Network.eth0.SubnetMask=' + SM
  87. print w
  88. p = urllib2.urlopen(w)
  89. #text = p.read()
  90. #print text.splitlines()
  91. print 'Connetion will be loss'
  92. # Setting up IP ends
  93.  
  94. ip_count += 1
  95.  
  96. # f = urllib2.urlopen('http://%s/%s'%(address,"cgi-bin/configManager.cgi?action=getConfig&name=VideoColor"))
  97. #text = f.read()
  98. # print text.splitlines()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement