1

Context

I check open ports on my server with a scheduled batch file:

nmap.exe server1 server2 server3 etc >> log.txt

Usually 21, 22, 80, 443 and 3389 are opened.

Now I want to send an email if only other ports are opened.

I saw there is Nmap Script Engine but I didn't find examples to understand... Also I would like to use batch if possible because I have already developed email mailings with this language (Blat).

Questions

  • How to filter "all ports except 21, 22, 80, 443, 3389"?
  • How to develop "for server x, if one port are opened, send email"?
GG.
  • 187
  • 1
  • 9

2 Answers2

2

Sounds like a fairly simple script, though if you're going to scan all 65535 ports you're going to find that it takes awhile for the scan to complete.

The Nmap Reference Guide is your friend here. The "greppable" output option (-oG) produces a file that is easy to parse with grep or Windows findstr.exe. You should be able to use these tools to filter the output to exclude the "expected ports" and send email (using something like blat) based on the remaining output.

Evan Anderson
  • 141,881
  • 20
  • 196
  • 331
  • Thanks for this answer. I asked an other question [here](http://stackoverflow.com/questions/9198226), maybe you know... – GG. Feb 08 '12 at 17:19
2

I covered a similar problem here on my blog, where I used the Ndiff tool to generate lists of new ports. Ndiff requires Python, but should work on Windows if you install Python. My particular script may not work with the latest version of Ndiff, but the idea is the same, and should fit your purposes.

bonsaiviking
  • 4,420
  • 17
  • 26