-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractCCTV.ps1
More file actions
81 lines (61 loc) · 3.44 KB
/
Copy pathextractCCTV.ps1
File metadata and controls
81 lines (61 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
param(
[string]$NVR_IP,
[string]$User,
[string]$Pass
)
# =================================================================> START GET DEVICE INFO
[xml]$getNvrDeviceInfo = curl.exe -sS --digest -u "$User`:$Pass" "http://$NVR_IP/ISAPI/System/deviceInfo"
$DeviceName = $getNvrDeviceInfo.deviceInfo.deviceName
# =================================================================> START GET DEVICE TOTAL CHANNEL
[xml]$getDeviceCapabilities = curl.exe -sS --digest -u "$User`:$Pass" "http://$NVR_IP/ISAPI/System/capabilities"
$capNode = $getDeviceCapabilities.SelectSingleNode("//*[local-name()='RacmCap']/*[local-name()='inputProxyNums']")
$totalChannels = if ($capNode) { [int]$capNode.InnerText } else { 0 }
# =================================================================> START GET TTL USED CHANNELS (STATUS)
[xml]$getNvrChannelsStatus = curl.exe -sS --digest -u "$User`:$Pass" "http://$NVR_IP/ISAPI/ContentMgmt/InputProxy/channels/status"
$statusNodes = $getNvrChannelsStatus.SelectNodes("//*[local-name()='InputProxyChannelStatus']/*[local-name()='id']")
$ttlUsedChannels = if ($statusNodes) { $statusNodes.Count } else { 0 }
$unUsedChannels = $totalChannels - $ttlUsedChannels
# =================================================================> START GET CAMERA LIST (CONFIG + STATUS)
[xml]$getNvrChannelsConfig = curl.exe -sS --digest -u "$User`:$Pass" "http://$NVR_IP/ISAPI/ContentMgmt/InputProxy/channels"
$cameraList = @()
$configNodes = $getNvrChannelsConfig.SelectNodes("//*[local-name()='InputProxyChannel']")
if ($configNodes) {
foreach ($node in $configNodes) {
$camIdNode = $node.SelectSingleNode("*[local-name()='id']")
$camNameNode = $node.SelectSingleNode("*[local-name()='name']")
$camIpNode = $node.SelectSingleNode("*[local-name()='sourceInputPortDescriptor']/*[local-name()='ipAddress']")
$camId = if ($camIdNode) { $camIdNode.InnerText.Trim() } else { "N/A" }
$camName = if ($camNameNode) { $camNameNode.InnerText.Trim() -replace "[\r\n\t]", " " } else { "Unknown" }
$camIp = if ($camIpNode) { $camIpNode.InnerText.Trim() } else { "N/A" }
$statusNode = $getNvrChannelsStatus.SelectSingleNode("//*[local-name()='InputProxyChannelStatus'][*[local-name()='id']='$camId']")
$onlineNode = if ($statusNode) { $statusNode.SelectSingleNode("*[local-name()='online']") } else { $null }
$camStatus = if ($onlineNode) {
if ($onlineNode.InnerText.Trim().ToLower() -eq "true") { "Online" } else { "Offline" }
} else {
"Unknown"
}
$cameraList += [PSCustomObject]@{
ID = [int]$camId
Name = $camName
IP = $camIp
Status = $camStatus
}
}
}
# =================================================================> OUTPUT
$report = @()
$report += ""
$report += "==================== NVR SUMMARY ===================="
$report += "Device: $DeviceName | IP: $NVR_IP"
$report += "Channels: Used $ttlUsedChannels | Unused $unUsedChannels | Total $totalChannels"
$report += "====================================================="
$report += ""
if ($cameraList.Count -gt 0) {
$report += "Attached CCTV Cameras:"
$tableString = $cameraList | Sort-Object ID | Format-Table -Property ID, Name, IP, Status -AutoSize | Out-String -Width 4096
$report += $tableString.TrimEnd()
} else {
$report += "No attached CCTV cameras found."
}
$report += ""
Write-Output $report