1

I have a newline separated list of domains that I would like to perform an arbitrary nmap scan on (e.g. aggressive, syn) and I would like to output a boolean that indicates whether or not any ports are open. The primary function here is to deduce whether a server is up even if it is ping blocking.

Is there a common pattern to accomplish this?

I am using the following to put the results into a monolithic XML file, but stanzas are not connected.

 mkdir results ; for ip in `cat servers`; do nmap -oX results/${ip}.xml -T4 -A $ip; done
4

Consider this command:

nmap 127.0.0.1 -T4 -p 111 -sT -oG - | awk | awk '/^Host: .* Status:.*Up/ { print $2" UP" }'

A common pattern using shell scripting is to use grepable output.

Use the flags "-oG -", the final dash is to redirect output to stdout.

Output from "-oG -" in this example outputs the following when I ran it at my own server:

Host: 127.0.0.1 (localhost) Status: Up

The output is redirected to awk, where it searches for strings starting with "Host:, and contain open ports.

When this pattern is found, awk will print:

127.0.0.1 UP
  • Please explain the command and the options you're suggesting. Without description, the value that can be obtained by another visitor is quite limited. – Xander Oct 20 '14 at 20:10
  • 1
    FYI for the purposes of showing whether something is up, you could have simplified it to: nmap 127.0.0.1 -T4 -p 22 -sT -oG - | awk '/Up/' – munkeyoto Oct 22 '14 at 14:27
  • @munkeyoto, excellent point! Updating answer for this – Dog eat cat world Oct 22 '14 at 16:37
1

I used something like this (powershell script) recently to determine simply if the server receives a response back. i know it's not nmap but it is quick and easy.

$erroractionpreference = 'silentlycontinue'
$import = import-csv 'config-network device.csv'
$collection = $()
   foreach ($HostName in $import)
    {
       $status = @{ "ServerName" = $Hostname.HostName; "TimeStamp" = (Get-Date -f s) }
       if (Test-Connection $Hostname.Hostname -Count 2 -ea 0 -Quiet)
    { 
       $status["Results"] = "Up"
    } 
       else 
    { 
       $status["Results"] = "Down" 
    }
       New-Object -TypeName PSObject -Property $status -OutVariable serverStatus
       $collection += $serverStatus

    }
      $collection | Export-Csv .\ServerStatus-networkALL2.csv -NoTypeInformation

You import from CSV. in your case $hostname might be the list of IP addresses you have or Hostnames.

Provides a simple output that says "up" or "down" depending on whether a response is received.

you can adjust the -count to determine how many pings should be sent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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