Shell script:
Obtain IP Address of a Network Interface: User input interface Output should be: $ ./admino -i en0 Your ip for en0 interface is:10.0.1.10
Answer:
for iface in $(ifconfig | cut -d ' ' -f1| tr '\n' ' ')
do
addr=$(ip -o -4 addr list $iface | awk '{print $4}' | cut -d/ -f1)
printf "Your ip for $iface interface is: $addr"
done
Output:
Please give thumbsup, or do comment in case of any query. Thanks.
Get Answers For Free
Most questions answered within 1 hours.