File: //ibin/iplist
#!/bin/bash
# Get the full hostname
full_hostname=$(hostname)
# Extract the subdomain part (excluding the domain)
subdomain=$(echo $full_hostname | cut -d. -f1)
#ifconfig|gawk '/inet/{print $2}'|gawk -F : '//{print $2}'
#To sort the output:
#ifconfig|gawk '/inet/{print $2}'|gawk -F : '//{print $2}'|sort
#To save it to a file:
#ifconfig|gawk '/inet/{print $2}'|gawk -F : '//{print $2}' > myiplist.txt
echo -e "Server: $subdomain ip addresses:"
# Newest list method
#ifconfig | awk '/inet / && $2 !~ /^127\./ {print $2}'
#ip -4 address | awk '/inet / && $2 !~ /^127\./ {print $2}'
ip -4 address | awk '/inet / && $2 !~ /^127\./ {split($2, a, "."); sub(/\/[0-9]+$/, "", a[4]); print a[1]"."a[2]"."a[3]"."a[4]}'