On Ubuntu OS, I'm trying to grab different input, do something with that input, but then output the variables in order. I thought this would be easy, but my searches are coming up nil.
The idea is to get a list of connected IP's and update the screen. I want to see the IP's, protocols and hostnames that are connecting to a server and show this list on screen live as it happens.
This is what I have so far, it doesn't look very pretty. Protocol prints all ports on one line.
#!/bin/bash
#
while true; do
clear
#echo -e "Press Ctrl + c to quit \n"
ip=$(netstat -natu | grep 'ESTABLISHED' | cut -d: -f2 | awk '{print$2}')
prot=$(netstat -tu | grep 'ESTABLISHED' | cut -d: -f2 | awk '{print$1}')
echo -e Protocol "\t" IP Address "\t" Name
for n in $ip; do
nbt=$(nbtscan $n | awk '{print $2}' | tail -1)
echo -e $prot "\t" $n "\t" $nbt #> connections.txt
done
sleep 2
done
Output shows
Protocol IP Address Name
ssh ftp 192.168.1.254 TIS-ADMIN02
ssh ftp 192.168.1.197 TRAINING2
it should show this
Protocol IP Address Name
ssh 192.168.1.254 ADMIN02
ftp 192.168.1.197 TRAINING2