Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


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).


  • How to filter "all ports except 21, 22, 80, 443, 3389"?
  • How to develop "for server x, if one port are opened, send email"?
share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
Thanks for this answer. I asked an other question here, maybe you know... – GG. Feb 8 '12 at 17:19

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.