Last active
December 8, 2018 21:05
-
-
Save dapacruz/03949f96cbbd040cc7e69178a720c51a to your computer and use it in GitHub Desktop.
Firewall Migration Validation
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
| $services = Import-Csv -Path Services.csv | |
| $fname = "Report-$(get-date -f yyyyMMdd.HHmmss).json" | |
| $report = @() | |
| # Export services to JSON for readability | |
| ConvertTo-Json -InputObject $services | Out-File -FilePath Services.json -Force -Confirm:$false | |
| foreach ($svc in $services) { | |
| foreach ($addr in $svc.Destination_Address.split(',')) { | |
| $obj = New-Object -TypeName PSObject | |
| Add-Member -InputObject $obj -MemberType NoteProperty -Name Rule_Number -Value $svc.Rule_Number | |
| Add-Member -InputObject $obj -MemberType NoteProperty -Name Name -Value $svc.Name | |
| Add-Member -InputObject $obj -MemberType NoteProperty -Name Destination_Address -Value $addr | |
| foreach ($port in $svc.TCP_Ports.split(',')) { | |
| Write-Host "Scanning host $addr TCP/$port ... " -NoNewline | |
| $tcp_client = New-Object System.Net.Sockets.TCPClient | |
| $c = $tcp_client.BeginConnect($addr, $port, $null, $null) | |
| $c.AsyncWaitHandle.WaitOne((New-TimeSpan -Seconds 1)) | Out-Null | |
| if ($tcp_client.Connected) { | |
| Write-Host 'open' | |
| Add-Member -InputObject $obj -MemberType NoteProperty -Name $port -Value 'open' | |
| } else { | |
| Write-Host 'filtered' | |
| Add-Member -InputObject $obj -MemberType NoteProperty -Name $port -Value 'filtered' | |
| } | |
| } | |
| Write-Host | |
| $report += $obj | |
| } | |
| } | |
| ConvertTo-Json -InputObject $report | Out-File -FilePath $fname |
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
| Rule_Number | Name | Destination_Address | TCP_Ports | |
|---|---|---|---|---|
| 1 | MailServer | 1.1.1.1 | 25 | |
| 2 | WebServer | 1.1.1.2 | 80,443 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment