-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenOS Port Objects
31 lines (26 loc) · 1.39 KB
/
ScreenOS Port Objects
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
Write-Host "Make the following manually:"
Get-Content .\TECH.txt | Select-String -Pattern '^set\s+service\s+".+?"\s+protocol\s+(?!(tcp|udp)).*'
Write-Host " "
Write-Host " "
Write-Host "Discontiguous port ranges are not supported Create Port object groups for the following:"
Get-Content .\TECH.txt | Select-String -Pattern '^set\s+service\s+".+?"\s+\+.*'
$PortObjects = @()
(Get-Content .\TECH.txt | Select-String '^set\s+service\s+".+?"\s+protocol\s+(tcp|udp).*') | ForEach-Object {
$name = @()
$protocol = @()
$port = @()
$name = $_ -replace '^set\s+service\s+"(.+)"\s+protocol\s+(tcp|udp)\s+src-port\s+(\d+\-\d+)\s+dst-port\s+(\d+\-\d+)','$1'
$protocol = $_ -replace '^set\s+service\s+"(.+)"\s+protocol\s+(tcp|udp)\s+src-port\s+(\d+\-\d+)\s+dst-port\s+(\d+\-\d+)','$2'
$port = $_ -replace '^set\s+service\s+"(.+)"\s+protocol\s+(tcp|udp)\s+src-port\s+(\d+\-\d+)\s+dst-port\s+(\d+\-\d+)','$4'
$name = $name -replace '\s+$',''
$name = $name -replace '(\\|\/|\s)','_'
[int]$bPort = ($port -split '-')[0]
[int]$ePort = ($port -split '-')[1]
if ($bPort -eq $ePort) { $port = $ePort }
$PortObject = New-Object psobject
$PortObject | Add-Member -MemberType NoteProperty -Name name -Value $name
$PortObject | Add-Member -MemberType NoteProperty -Name protocol -Value $protocol
$PortObject | Add-Member -MemberType NoteProperty -Name port -Value $port
$PortObjects += $PortObject
}
$PortObjects