I am trying to match output from Nmap command using Regexp. There can be two different formats.
1st format (when nmap can find hostname)
Nmap scan report for 2u4n32t-n4 (192.168.2.168)
and 2nd format (without hostname)
Nmap scan report for 192.168.2.1
I want to capture both hostname and ipaddress and if there is no hostname just get Ip as the hostname as in the 2nd format.
What I was trying in Regexp so far in golang is
Nmap scan report for\\s+([^[:space:]]+)(\\s+\\(([^[:space:]]+)\\))?
But what I got as a result in golang
The 1st format ( it gave me (192.168.2.168)
which I don't want ) is as follow:
[Nmap scan report for 2u4n32t-n4 (192.168.2.168), 2u4n32t-n4 , (192.168.2.168) , 192.168.2.168]
and the 2nd format ( it gave me which I don't want ) is as follow:
[Nmap scan report for 192.168.2.1, 192.168.2.1, ]
What to do correctly?