Discovering Raspberry PI in Local Network

Today I reconnected a Raspberry PI 5 that I setup some time ago into my network as a headless device, of course I needed to know its IP address in order to connect to it via SSH.

It ocurred to me that I could scan my network before connecting the device and also after in order to identify the new IP address. Here are commands I use (you may adjust your network mask if needed):

sudo nmap -sn 192.168.1.0/24 -oG - | awk '/Up$/{print $2}' | sort > before.txt

After connecting the Raspberry PI 5 I ran this command:

sudo nmap -sn 192.168.1.0/24 -oG - | awk '/Up$/{print $2}' | sort > after.txt

Then to reveal the differences I used this command:

comm -13 before.txt after.txt

It did reveal my new IP address and since I configured it for SSH access via SSH key I had the conguration already in my local SSH configuration.

That is it.