xxxxxxxxxx
# Method 1: Using ip command
ip addr show
# Method 2: Using ifconfig command
ifconfig
xxxxxxxxxx
ip_address=$(hostname -I | awk '{print $1}')
echo "IP address: $ip_address"
xxxxxxxxxx
import socket
# get the hostname
hostname = socket.gethostname()
# get the IP address
ip_address = socket.gethostbyname(hostname)
print(f"The IP address of this Ubuntu machine is: {ip_address}")