Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine which IPs in a given range have port 80 using nmap?

Tags:

I'm new to bash scripting and I'm trying to get this working:

Scanning an IP range for finding devices with the port 80 open... I think it has to look like this:

#!/bin/bash echo ----------------------------------- for ip in 192.168.0.{1,.255}; do nmap -p80 192.168.0.1       if #open; then             echo "{ip} has the port 80 open"       else             #do nothing fi done echo ----------------------------------- exit 0 

I also just want to see the results like this:

----------------------------------- 192.168.0.1 has the port 80 open 192.168.0.10 has the port 80 open 192.168.0.13 has the port 80 open 192.168.0.15 has the port 80 open ----------------------------------- 

(So without errors or nmap's normal outputs..)

Can someone help me for this?

like image 952
bananah Avatar asked Sep 22 '10 20:09

bananah


2 Answers

nmap comes with a nice output parameter -oG (grepable output) which makes parsing more easy. Also it is not necessary to iterate through all IP addresses you want to scan. nmap is netmask aware.

Your example can be written as:

nmap -p80 192.168.0.0/24 -oG - | grep 80/open 

The -oG enables the grepable output, and - specifies the file to output to (in this case stdout). The pipe symbol redirects the output of nmap (stdout) to grep, which only returns lines containing 80/open in this case.

like image 85
Manuel Faux Avatar answered Sep 19 '22 10:09

Manuel Faux


Try this

nmap --open -p80 192.168.0.* 

The --open will only list host with port 80 open. This way you save having to check in your shell script as filtering is already done by nmap itself.

https://nmap.org/book/man-briefoptions.html

like image 45
Mohamed Avatar answered Sep 19 '22 10:09

Mohamed