right now my aim is to scan a single ip and get only the open ports printed in a single line seperated by commas.
The code below does that but it inject % at the end
The goal is to achieve port number in a single line as output without the last 2 characters (the last comma and % sign)
sudo nmap -vv -sS 10.129.208.16 -oG - | awk -v OFS=':' '
/open/ {
for (i=4;i<=NF;i++) {
split($i,a,"/");
if (a[2]=="open") {printf a[1]","}
}
}'
output :
21,22,53,80,139,443,445,%
required output:
21,22,53,80,139,443,445
New contributor
Nr-yolo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.