I am trying to display all services and their versions that runs on a host using ports from 1 to 1023, in this way:
ssh, OpenSSH 5.9p1 Debian 5ubuntu1 (protocol 2.0)
smtp, Postfix smtpd
http, Apache httpd 2.2.22 ((Ubuntu))
rpcbind
imap, Courier Imapd (released 2011)
ssl/imap, Courier Imapd (released 2011)
I know how to display them but not in the format above:
nmap -p 1-1023 -sV host
LATER EDIT:
I managed to display only the services without any extra unuseful text:
nmap -p 1-1023 -sV host | head -n -5 | tail -n +7
Which outputs:
8/tcp open http BitTornado tracker T-0.3.18
21/tcp open ftp vsftpd 2.3.5
22/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1 (protocol 2.0)
23/tcp open telnet Linux telnetd
25/tcp open smtp Postfix smtpd
80/tcp open http Apache httpd 2.2.22 ((Ubuntu))
111/tcp open rpcbind
143/tcp open imap Courier Imapd (released 2011)
158/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1.1 (protocol 2.0)
165/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1.1 (protocol 2.0)
177/tcp open ftp vsftpd 2.3.5
210/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1.1 (protocol 2.0)
993/tcp open ssl/imaps?
Now I am really curious how can I get rid of the first two columns.
This one works for sure, just tested it and it's exactly what you want:
index
finds the 3rd column and returns its position tosubstring
which then marks that position in whole line$0
. All of this is then sent toprint
which displays it. Default field separator in awk is whitespace (spaces, TABs, newlines) so no need in using -F switch.