Grep nmap open port IP

I am trying to make this script for grep open port IPs from nmap, but I cannot do it right.

I have something like this:

nmap 192.168.0.0/24 -sU -p 44555 | grep -oP "([0-9]{1,3}\.){3}[0-9]{1,3}"  >output.txt

But all this IP is open and closed.

Nmap output example:

Nmap scan report for 79-119-0-248.rdsnet.ro (79.119.0.248)
Host is up (0.033s latency).
PORT      STATE         SERVICE
27023/udp open|filtered unknown

Nmap scan report for 79-119-0-249.rdsnet.ro (79.119.0.249)
Host is up (0.032s latency).
PORT      STATE  SERVICE
27023/udp closed unknown

Only open / filtered I want Thanks

+4
source share
4 answers

It works with egrep:

nmap 192.168.0.0/24 -sU -p 44555 | grep -B3 open | egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}"  > output.txt
+3
source

If you want to just get open ip , you can try the following code (certainly works):

nmap 192.168.0.0/24 -sU -p 44555 | grep '^44555.*open' -B3 | grep '^Nmap scan' | cut -d\( -f2 | cut -d\) -f1 > output.txt
0
source

awk

nmap 192.168.0.0/24 -sU -p 44555|awk  '/(open|filtered)/{print $2}' RS="Nmap" FS="[)(]"

  • RS="Nmap" - Nmap
  • FS="[)(]"
  • /(open|filtered)/{print $2}If the entry has openor filtered, print column 2.
0
source

-oG and nmap will do this for you. Everyone should always try to complicate the situation, and there is no reason for this.

0
source

All Articles