Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com

This Blog is protected by DMCA.com

huuphan.com. Powered by Blogger.

Bash script list all IP addresses connected to Server

Running to bash script list all IP addresses connected to Server
./studyscript.sh  >/dev/null 2>&1






The bash script list all IP addresses connected to Server
#!/bin/bash
rm -f /tmp/list_IP
rm -f /tmp/list_IPP
rm -f /tmp/list_IPdone
netstat -ntu | grep ESTA | awk -F: '{ print $2 }' | sed -r 's/^.{12}//' |sed 's/:/\n/g' | sed '/^\s*$/d'| sort > /tmp/list_IP
#sleep 10
while read -r p
do
 curl ipinfo.io/$p
done < /tmp/list_IP >/tmp/list_IPP

cat /tmp/list_IPP | egrep "ip|country" |sed '$!N;s/\n/ /' |sed -r 's/^.{9}//' |sed 's/"country": "//' |sed 's/",//g' >> /tmp/list_IPdone
echo "-----IP------  --country--" >> /tmp/list_IPdone

Note the bash script list all IP addresses connected to Server
sed 's/:/\n/g' Delete duplicate lines
sed '/^\s*$/d' Delete empty lines
sed '$!N;s/\n/ /' How to merge every two lines into one from the command line

The result bash script list all IP addresses connected to Server
cat /tmp/list_IPdone
As the output below

113.171.72.17   VN
172.217.24.212   US
172.217.24.46   US
172.217.25.14   US
216.58.197.100   US
216.58.199.14   US
216.58.199.14   US
216.58.200.2   US
216.58.200.3   US
216.58.200.9   US
216.58.203.35   US
216.58.212.131   US
216.58.221.110   US
31.13.95.12   IE
31.13.95.36   IE
31.13.95.8   IE
-----IP------  --country--
Bash script list all IP addresses connected to Server

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com