Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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"?
share|improve this question
add comment

2 Answers 2

up vote 1 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
add comment

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
add comment

Your Answer

 
discard

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.