Hello All
These are diffrent columns in my fingerprinting tool.Look at code lines pls.
DUP
/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|sed -n '2,$p'|awk '{print $1$2}'
Protocol
echo "udp"
Local IP
A=$(/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|awk -F' ' '{if ($1$2 == "@@Host NWStats.DUP@@" ) print $1}')
B=`echo "$A"|grep "*"|wc -l`
if [ $B = 1 ]
then
C=`echo "$A"|cut -d "." -f1`
echo "$C"
fi
if [ $B = 0 ]
then
D=`echo "$A"|cut -d "." -f1-4`
echo "$D"
fi
Local Port
A=$(/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|awk -F' ' '{if ($1$2 == "@@Host NWStats.DUP@@" ) print $1}')
B=`echo "$A"|grep "*"|wc -l`
if [ $B = 1 ]
then
C=`echo "$A"|cut -d "." -f2`
echo "$C"
fi
if [ $B = 0 ]
then
D=`echo "$A"|cut -d "." -f5`
echo "$D"
fi
Remote IP
echo "NULL"
Remote Port
echo "NULL"
State
A=$(/usr/bin/netstat -an -f inet -P udp|egrep -v "UDP|Local|--"|awk -F' ' '{if ($1$2 == "@@Host NWStats.DUP@@" ) print $2}')
echo "$A"
Issue:
Above lines have been written to get all UDP data in a CSV.
e.g
bash-3.00$ /usr/bin/netstat -an -f inet -P udp
UDP: IPv4
Local Address Remote Address State
-------------------- -------------------- ----------
*.48517 Idle
*.* Unbound
*.161 Idle
*.111 Idle
*.* Unbound
*.33270 Idle
*.* Unbound
*.* Unbound
*.33271 Idle
*.4045 Idle
*.5000 Idle
*.5000 Idle
*.5000 Idle
When i run the code,it fumbles up at these three lines
*.5000 Idle
*.5000 Idle
*.5000 Idle
because both colmuns in all 3 rows are identical.
How can i modify code lines to capture all three rows as it is?
I am facing same issue for capturing data for TCP
/usr/bin/netstat -an -f inet -P tcp
I want the commands data as it is in my CSV ,without losing any of it?
Kindly advice.
Regards
Abhi