How to Get IP Address Using Bash Script
Introduction
The ipconfig command is a useful tool for displaying information about your network configuration. It can be used to show your IP address, subnet mask, default gateway, and other information. However, the ipconfig command only shows information about the network interface that is currently being used. If you want to get information about all of the network interfaces on your system, you can use a Bash script.
Bash Script
#!/bin/bash # Get the list of network interfaces interfaces=( $(ifconfig | grep '^[a-z]' | awk '{print $1}') ) # Iterate over the network interfaces for interface in "${interfaces[@]}" do # Get the IP address for the interface ip_address=$(ifconfig $interface | grep 'inet addr:' | awk '{print $2}' | cut -d '/' -f 1) # Print the IP address for the interface echo "$interface: $ip_address" done
Comments