-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnmapdiff.ps1
More file actions
49 lines (37 loc) · 1.3 KB
/
Copy pathnmapdiff.ps1
File metadata and controls
49 lines (37 loc) · 1.3 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
<#
.SYNOPSIS
.DESCRIPTION
.PARAMETER target
List of NMap Tragets you want to scan
.PARAMETER options
NMap options to be added to the default scan
.EXAMPLE
.\nmapdiff.ps1 -target 192.168.1.0/24
.NOTES
#>
param (
[Parameter(Mandatory=$true)][string] $target
)
$options = ""
$smtpServer=""
$from = ""
$Recipient = ""
if ( Test-Path baselinescan.xml ) {
Write-Host "<<< Creating delta scan. >>>"
Invoke-Expression "& nmap $target $options -n -oX deltascan.xml" > $null
$ndiff = (ndiff baselinescan.xml deltascan.xml) | Out-String
$ndiff.TrimEnd() > ndiff.txt
$filtered = Get-Content .\ndiff.txt | select-string -pattern "Nmap" -NotMatch
if ( $filtered -ne $null) {
write-host "<<< Changes found in delta -vs- baseline. Sending Email. >>>" -ForegroundColor Yellow
Send-Mailmessage -smtpServer $smtpServer -from $from -to $recipient -subject "NMap Changes found" -body $ndiff -priority High -UseSsl
} else {
Write-Host "<<< No changes in delta scan -vs- baseline. Closing. >>>" -ForegroundColor Green
}
Remove-Item .\ndiff.txt
Remove-Item baselinescan.xml
Rename-Item deltascan.xml baselinescan.xml
} else {
Write-Host "Creating First Baseline Scan"
Invoke-Expression "& nmap $target $options -n -oX baselinescan.xml" > $null
}