How to Find Your Raspberry Pi’s IP Address Without a Monitor (Headless Setup)

If you’ve just plugged your Raspberry Pi into your network with no monitor, no keyboard, and no mouse (headless setup), you still need its IP address to connect via SSH.

Instead of guessing or logging into your router’s admin page, you can quickly scan your local network with Python to find your Pi — even if you don’t know its IP.

Why This Works

This Python script:

  • Auto-detects your local subnet (e.g., 192.168.1.x)
  • Pings all devices to see which are online
  • Checks SSH (port 22) to find devices you can connect to immediately

Perfect for finding a newly plugged-in Raspberry Pi that has SSH enabled.

Python Script to Find Raspberry Pi IP Address

Save this as find_pi.py:

import socket
import platform
import subprocess
from concurrent.futures import ThreadPoolExecutor, as_completed

def get_prefix():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    ip = s.getsockname()[0]
    s.close()
    return ".".join(ip.split(".")[:3])

def ping(ip):
    system = platform.system().lower()
    cmd = ["ping", "-n", "1", "-w", "400", ip] if "windows" in system else ["ping", "-c", "1", "-W", "1", ip]
    return subprocess.run(cmd, stdout=subprocess.DEVNULL).returncode == 0

def check_ssh(ip):
    try:
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.settimeout(0.3)
            return s.connect_ex((ip, 22)) == 0
    except:
        return False

if __name__ == "__main__":
    prefix = get_prefix()
    print(f"Scanning {prefix}.1-254...")
    alive = []

    with ThreadPoolExecutor(max_workers=100) as ex:
        futures = {ex.submit(ping, f"{prefix}.{i}"): f"{prefix}.{i}" for i in range(1, 255)}
        for fut in as_completed(futures):
            ip = futures[fut]
            if fut.result():
                alive.append(ip)
                print(f"Alive: {ip}")

    print("\nChecking for SSH...")
    for ip in alive:
        if check_ssh(ip):
            print(f"SSH open: {ip}")

How to Use

  1. Enable SSH on your Raspberry Pi
    • Create an empty file named ssh (no extension) on the /boot partition of your SD card.
  2. Install Python on your computer if not already installed.
  3. Save the script as find_pi.py.
  4. Open a terminal/command prompt and run:
    python find_pi.py
  5. Look for:
    SSH open: 192.168.1.14

That’s your Pi’s IP. Connect with:
ssh pi@192.168.1.14