Last active
March 2, 2016 14:01
-
-
Save b4tman/94e05d213b513eab3e1e to your computer and use it in GitHub Desktop.
PowerShell скрипт для быстрой (дата/время, аудио/видео) настройки IP-камер
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" | |
Скрипт используется для быстрой (дата/время, аудио/видео) настройки всех камер | |
Заполните количество и нажмите Настроить. | |
IP камер генерируются по порядку на основании количества камер | |
начиная от 192.168.254.10 | |
Выполняет GET запросы в веб интерфейс на каждую камеру | |
Используется фиксированная базовая авторизация пользователь admin | |
без пароля | |
" | |
# параметр - кол-во камер | |
[int] $cams_count = 2 | |
Add-Type -assembly System.Windows.Forms | |
function _request([string] $ip, [string] $req='/') | |
{ | |
$apiUrl = New-Object System.Uri(('http://{0}{1}' -f $ip, $req)) | |
$request = [System.Net.HttpWebRequest]::Create($apiUrl) | |
$request.Method = "GET" | |
$request.Host = $ip | |
$request.UserAgent = 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0' | |
$request.Accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' | |
$request.Headers.Add('Accept-Language', 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3') | |
$request.Referer = 'http://{0}/setup.htm' -f $ip | |
$request.Headers.Add('Cookie', 'MP_MODE=1') | |
$request.Credentials = New-Object System.Net.NetworkCredential('admin','') | |
$response = $request.GetResponse() | |
if ($null -eq $response) {return $null} | |
$responsestream = $response.GetResponseStream() | |
$readStream = New-Object System.IO.StreamReader($responsestream, [System.Text.Encoding]::UTF8) | |
$result = $readStream.ReadToEnd | |
$response.Close | |
$readStream.Close | |
return $result | |
} | |
function cam_ip([int] $nn) | |
{ | |
return '192.168.254.{0}' -f ($nn + 10) | |
} | |
function cam_set_date([string] $cam) | |
{ | |
$req = '/vb.htm?language=ie&wintimezone=109&timefrequency=0&{0}&setdaylight=0' -f (Get-Date -Format \"new\da\te="yyyy_M_d\"&new\ti\me="H"\%3A"m"\%3A"s) | |
return _request -ip $cam -req $req | |
} | |
function cam_set_AV_aspect([string] $cam) | |
{ | |
$req_aspect = '/vb.htm?language=ie&profilenumber=2&aspectratio=4:3&videocodec=1' | |
return _request -ip $cam -req $req_aspect | |
} | |
function cam_set_AV_profiles([string] $cam) | |
{ | |
$req_profiles = '/vb.htm?language=ie&profile1format=H.264&profile1resolution=1440x1080&profile1view=1440x1080&profile1rate=7&profile1qmode=0&profile1bps=1M&profile2format=H.264&profile2resolution=640x480&profile2view=640x480&profile2rate=15&profile2qmode=0&profile2bps=512K&audiotype=G.711&audioinenable=0&micgain=20dB&audiooutenable=0&audiooutvolume=10&videocodec=1' | |
return _request -ip $cam -req $req_profiles | |
} | |
function ui_trap([string] $cam, [string] $func) | |
{ | |
write-host -NoNewline ('{0}: ' -f $cam) | |
trap { | |
Write-Host -ForegroundColor red "ОШИБКА" | |
return | |
} | |
Invoke-Expression -command ('{0}("$cam")' -f $func) | |
Write-Host -ForegroundColor green 'OK' | |
} | |
function ui_progress([int] $nn, [string] $func, [string] $desc) | |
{ | |
[string] $cam = cam_ip($nn); | |
$ProgressBar.Value = 100*$nn/$cams_count | |
Write-Progress -Activity $desc -Status 'Выполнение...' -PercentComplete (100*$nn/$cams_count) -CurrentOperation $cam | |
ui_trap -cam $cam -func $func | |
} | |
function setup() | |
{ | |
Write-Host '-- Дата/Время: ' | |
for ($i=0; $i -lt $cams_count; $i++) { ui_progress -desc '[1/3] Установка даты и времени' -nn $i -func 'cam_set_date' } | |
Write-Host '_____________________' | |
Write-Host '-- Аудио/Видео (соотношение сторон): ' | |
for ($i=0; $i -lt $cams_count; $i++) { ui_progress -desc '[2/3] Установка параметров Аудио/Видео (соотношение сторон)' -nn $i -func 'cam_set_AV_aspect' } | |
Write-Host '-- Аудио/Видео (профили потоков): ' | |
for ($i=0; $i -lt $cams_count; $i++) { ui_progress -desc '[3/3] Установка параметров Аудио/Видео (профили потоков)' -nn $i -func 'cam_set_AV_profiles' } | |
$ProgressBar.Value = 100 | |
} | |
$MainWindow = New-Object System.Windows.Forms.Form | |
$SetupButton = New-Object System.Windows.Forms.Button | |
$CloseButton = New-Object System.Windows.Forms.Button | |
# Текстовые поля и списки | |
$CountTextBox = New-Object System.Windows.Forms.ComboBox | |
# Подписи | |
$CountTextBoxLabel = New-Object System.Windows.Forms.Label | |
# Описываем свойства | |
# Главная форма | |
$MainWindow.StartPosition = "CenterScreen" | |
$MainWindow.Text = "Быстрая настройка IP камер D-Link для ЕГЭ" | |
$MainWindow.Width = 470 | |
$MainWindow.Height = 220 | |
$MainWindow.Autosize = 1 | |
$MainWindow.AutoSizeMode = "GrowAndShrink" | |
# Подписи к текстовым полям | |
$CountTextBoxLabel.Location = New-Object System.Drawing.Point(10,12) | |
$CountTextBoxLabel.Text = "Количество камер" | |
$CountTextBoxLabel.Autosize = 1 | |
# Описание текстбокса | |
$CountTextBox.Location = New-Object System.Drawing.Point(140,10) | |
$CountTextBox.Width = 300 | |
# Обработка события - при смене текста в поле, присваиваем переменной новое полученное значение. | |
$CountTextBox.add_TextChanged({ $cams_count = [int] $CountTextBox.Text }) | |
$CountTextBox.TabIndex = 1 | |
$CountTextBox.Text = $cams_count | |
$SetupButton.Location = New-Object System.Drawing.Point(10,150) | |
$SetupButton.Text = "Настроить" | |
$SetupButton.add_click({setup} ) | |
$SetupButton.Autosize = 1 | |
$SetupButton.TabIndex = 2 | |
$CloseButton.Location = New-Object System.Drawing.Point(315,150) | |
$CloseButton.Text = "Закрыть" | |
$CloseButton.add_click({ $MainWindow.Close() }) | |
$CloseButton.Autosize = 1 | |
$CloseButton.TabIndex = 3 | |
$ProgressBar = New-Object System.Windows.Forms.ProgressBar | |
$ProgressBar.Location = New-Object System.Drawing.Point(10,70) | |
$ProgressBar.Value = 0 | |
$ProgressBar.Width = 430 | |
# Добавляем контролы в форму и вызываем её запуск | |
$MainWindow.Controls.Add($SetupButton) | |
$MainWindow.Controls.Add($CloseButton) | |
$MainWindow.Controls.Add($CountTextBox) | |
$MainWindow.Controls.Add($CountTextBoxLabel) | |
$MainWindow.Controls.Add($ProgressBar) | |
$MainWindow.Controls.Add($ProgressLabel) | |
$MainWindow.ShowDialog() | Out-Null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" | |
Скрипт используется для быстрой (дата/время, аудио/видео) настройки всех камер | |
IP камер генерируются по порядку на основании параметра cams_count | |
начиная от 192.168.254.10 | |
Параметр cams_count - число - количество камер | |
Выполняет GET запросы в веб интерфейс на каждую камеру | |
Используется фиксированная базовая авторизация пользователь admin | |
без пароля | |
" | |
# параметр - кол-во камер | |
New-Variable -Name cams_count -Value 24 -Option Constant | |
function _request([string] $ip, [string] $req='/') | |
{ | |
$apiUrl = New-Object System.Uri(('http://{0}{1}' -f $ip, $req)) | |
$request = [System.Net.HttpWebRequest]::Create($apiUrl) | |
$request.Method = "GET" | |
$request.Host = $ip | |
$request.UserAgent = 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0' | |
$request.Accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' | |
$request.Headers.Add('Accept-Language', 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3') | |
$request.Referer = 'http://{0}/setup.htm' -f $ip | |
$request.Headers.Add('Cookie', 'MP_MODE=1') | |
$request.Credentials = New-Object System.Net.NetworkCredential('admin','') | |
$response = $request.GetResponse() | |
if ($null -eq $response) {return $null} | |
$responsestream = $response.GetResponseStream() | |
$readStream = New-Object System.IO.StreamReader($responsestream, [System.Text.Encoding]::UTF8) | |
$result = $readStream.ReadToEnd | |
$response.Close | |
$readStream.Close | |
return $result | |
} | |
function cam_ip([int] $nn) | |
{ | |
return '192.168.254.{0}' -f ($nn + 10) | |
} | |
function cam_set_date([string] $cam) | |
{ | |
$req = '/vb.htm?language=ie&wintimezone=109&timefrequency=0&{0}&setdaylight=0' -f (Get-Date -Format \"new\da\te="yyyy_M_d\"&new\ti\me="H"\%3A"m"\%3A"s) | |
return _request -ip $cam -req $req | |
} | |
function cam_set_AV_aspect([string] $cam) | |
{ | |
$req_aspect = '/vb.htm?language=ie&profilenumber=2&aspectratio=4:3&videocodec=1' | |
return _request -ip $cam -req $req_aspect | |
} | |
function cam_set_AV_profiles([string] $cam) | |
{ | |
$req_profiles = '/vb.htm?language=ie&profile1format=H.264&profile1resolution=1440x1080&profile1view=1440x1080&profile1rate=7&profile1qmode=0&profile1bps=1M&profile2format=H.264&profile2resolution=640x480&profile2view=640x480&profile2rate=15&profile2qmode=0&profile2bps=512K&audiotype=G.711&audioinenable=0&micgain=20dB&audiooutenable=0&audiooutvolume=10&videocodec=1' | |
return _request -ip $cam -req $req_profiles | |
} | |
function ui-trap([string] $cam, [string] $func) | |
{ | |
write-host -NoNewline ('{0}: ' -f $cam) | |
trap { | |
Write-Host -ForegroundColor red "ОШИБКА" | |
return | |
} | |
Invoke-Expression -command ('{0}("$cam")' -f $func) | |
Write-Host -ForegroundColor green 'OK' | |
} | |
function ui_progress([int] $nn, [string] $func, [string] $desc) | |
{ | |
[string] $cam = cam_ip($nn); | |
write-progress -activity $desc -status 'Выполнение...' -percentcomplete (100*$nn/$cams_count) -currentOperation $cam | |
ui-trap -cam $cam -func $func | |
} | |
Write-Host '-- Дата/Время: ' | |
for ($i=0; $i -lt $cams_count; $i++) { ui_progress -desc 'Установка даты и времени' -nn $i -func 'cam_set_date' } | |
Write-Host '_____________________' | |
Write-Host '-- Аудио/Видео (соотношение сторон): ' | |
for ($i=0; $i -lt $cams_count; $i++) { ui_progress -desc 'Установка параметров Аудио/Видео (соотношение сторон)' -nn $i -func 'cam_set_AV_aspect' } | |
Write-Host '-- Аудио/Видео (профили потоков): ' | |
for ($i=0; $i -lt $cams_count; $i++) { ui_progress -desc 'Установка параметров Аудио/Видео (профили потоков)' -nn $i -func 'cam_set_AV_profiles' } | |
запуск: powershell -NoProfile -ExecutionPolicy unrestricted ./quick-cams-setup.ps1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
при скачивании сохраняется в UTF-8 без BOM, нужно пересохранить в кодировке UTF-8 с BOM или Windows-1251