Pi Awesome

Reference and guides to build kick ass raspberry pi projects.

View the Project on GitHub codingforentrepreneurs/Pi-Awesome

Get your IP Address or Hostname

Are you looking to find devices on network with macOS, linux, or windows?

macOS

In terminal run:

HOST_IP=$(ipconfig getifaddr en0)
echo $HOST_IP

Verify with:

echo $HOST_IP

Linux / Raspberry Pi OS

Option 1 In terminal run:

HOST_IP1=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
echo $HOST_IP1

Verify with:

echo $HOST_IP1

Option 2

In terminal run:

HOST_IP2=$(hostname  -I | cut -f1 -d' ')

Verify with:

echo $HOST_IP2

Windows

In powershell run:

$env:HostIP = (
    Get-NetIPConfiguration |
    Where-Object {
        $_.IPv4DefaultGateway -ne $null -and
        $_.NetAdapter.Status -ne "Disconnected"
    }
).IPv4Address.IPAddress

Verify with:

$env:HostIP