1

Assume I am executing nmap shell to find out a simple output.We are all familiar with this one:

Starting Nmap 6.47 ( http://nmap.org ) at.... 
Nmap scan report for www.google.com (172.217.26.68)
Host is up (0.085s latency).
rDNS record for 172.217.26.68: sin10s02-in-f68.1e100.net
Not shown: 998 filtered ports
PORT    STATE SERVICE
80/tcp  open  http
443/tcp open  https

Nmap done: 1 IP address (1 host up) scanned in 9.38 seconds

Now I want the port state and service specifically For example:

Open ports are:
80
443

or something like this.The point is I want to use a specific output and use it somewhere else.Can anyone give me a very very simple example?

0

Try with this code:

echo "Open ports are: ";nmap $HOST |awk -F'/' '/open/ {print $1}'
0
$ echo 'Open ports are:';nmap localhost -oG -|grep -oP '[0-9]*(?=/open)'
Open ports are:
22
6000
0
your_nmap_cmd |
sed -ne '
  /^PORT/!d
  h;n              # grab PORT line & prepare for port info
  \|/|!q           # we are done once no / found so quitting
  s|/.* open .*||p # display port num only for open state
  G;D              # without reading next input goto top
'

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.