Domanda

I need load ip list from file, scan it, and create output format such as ip:port. I tried this:

nmap -iL mylistwithip.txt -p 80,21 -oG -PS 80,21 | awk '/open/{print $2}' >` output.txt

but it gives me only "open" and that's all.

While I need only opened ports from list of IP addresses, for example:

192.168.2.1
192.168.2.2
192.168.2.3

after scan ports, sample output.txt:

192.168.2.1:80
192.168.2.1:21
192.168.2.3:80

(only scanned ip addresses with opened ports)

È stato utile?

Soluzione 3

Quick and ugly hack to achieve that:

nmap -vv -iL mylistwithip.txt  | grep "Discovered open port" | awk {'print $6":"$4'} | awk -F/ {'print $1'} > output.txt

With -vv output includes lines like

Discovered open port 22/tcp on 192.168.2.1
Discovered open port 80/tcp on 192.168.2.1
Discovered open port 22/tcp on 192.168.2.107
Discovered open port 80/tcp on 192.168.2.107

First awk selects "ip address" and "port number/protocol" fields, and second cuts off "/protocol".

This will probably break in some future update of nmap. Using -sG (greppable output) would be a better idea.

Altri suggerimenti

Try this awk oneliner:

nmap -Pn -oG - 192.168.1.1 | awk '/open/{ s = $2; for (i = 5; i <= NF-4; i++) s = substr($i,1,length($i)-4) "\n"; split(s, a, "/"); print $2 ":" a[1]}'

try one more solution with single awk only.

nmap -vv -iL file  | awk -F'[ /]' '/Discovered open port/{print $NF":"$4}'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top