Killertechno
Posts: 181
Joined: Wed Jan 02, 2013 8:28 am

Detect IP and MAC of headless PI

Mon Dec 21, 2015 12:03 pm

Hi guys,
some time ago I've read there was a program to install on Pi to periodically send IP and MAC broadcast through UDP packets.
Then there was a GUI program as UDP server to detect ONLY Raspberry Pis on local network.
Now I can't find it anymore.

On forum I've found only scanners, but I have several PI running headless and ssh disabled.
May anyone help me?
Thanks.

danjperron
Posts: 3421
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Detect IP and MAC of headless PI

Mon Dec 21, 2015 12:18 pm

Do you mean avahi.

It is already installed.

Try on one of your PI.

Code: Select all

avahi-browse -r -a 

Normally they will be recognize with their hostname + ".local".
When I want to connect on my Pi2 I use "ssh pi@Pi2.local" or ping to my original RPi "ping FirstPi.local"

Of course I change the name of My Pi with sudo raspi-config.

I hope you put a different hostname on each of them!

User avatar
DougieLawson
Posts: 36560
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Detect IP and MAC of headless PI

Mon Dec 21, 2015 12:50 pm

Why not get your RPi to send an email when it boots up with the current IP address? No scanning (except of your inbox) needed.

You may need to install a mail program sudo apt-get install heirloom-mailx
Then a crude hostname -I | mail example@gmail.co.uk will send you the network details.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

ripat
Posts: 191
Joined: Tue Jul 31, 2012 11:51 am
Location: Belgium

Re: Detect IP and MAC of headless PI

Mon Dec 21, 2015 7:33 pm

Install arp-scan and do:

Code: Select all

sudo arp-scan --localnet | grep -i B8:27:EB
Using Linux command line usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

danjperron
Posts: 3421
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Detect IP and MAC of headless PI

Tue Dec 22, 2015 4:18 am

In case that avahi-browse didn't work , you need to install it

Code: Select all

sudo get-apt install avahi-utils
About arp-scan, maybe you will need to change which device scan.

On my Rasberry Pi, if I want to scan the network, I had to set the interface to wlan0 or br0 on my other Pi.

Code: Select all

sudo arp-scan -I wlan0  --localnet
So I made a little script in python to decipher what avahi-browse output

avahiScan.py

Code: Select all

import sys
import subprocess


cmd = ["avahi-browse", "-a","-r","-p","-t"]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)


IPv6=0
IPv4=0
IPDict={}

for line in iter(p.stdout.readline,b''):
      #check for the term .local
      if line.find('.local'):
         sline=line.split(';')
         if len(sline) >7:
           #now let's checkIP
           if not (sline[7] in IPDict):
              #ok let's add it
              IPDict[sline[7]]= [sline[1] , sline[6].replace('.local','')]
              if ':' in sline[7]:
                IPv6 = IPv6 + 1
              else:
                IPv4 = IPv4 + 1

# ok let's print it
if (IPv6+IPv4) == 0:
  print('No unit found!')

Header = ['\nIPv4:' , '\nIPv6:']
NCount = [ IPv4   , IPv6]
WhatChar = [ '.'  , ':']
IPSpacing = [ '16' , '40']

for idx in range(2):

 if NCount[idx] == 0:
    continue

 print(Header[idx])


 for ip  in IPDict:
  if WhatChar[idx]  in ip:
      print("{IP: <{fill}} : {device:<5} : {name}".format(IP=ip,fill=IPSpacing[idx],device=IPDict[ip][0],name=IPDict[ip][1]))


It takes around 6 seconds to get the answer

Code: Select all

pi@raspberrypi:~ $ python avahiScan.py

IPv4:
169.254.37.199   : eth0  : raspberrypi
10.11.12.119     : br0   : NAS1
10.11.12.193     : br0   : Pi2
10.11.12.123     : br0   : raspberrypi
169.254.16.177   : wlan0 : raspberrypi
10.11.12.191     : br0   : robot
10.11.12.192     : br0   : PiA
10.11.12.108     : br0   : MacBook-Air-de-Daniel
10.11.12.102     : br0   : NAS2
10.11.12.7       : br0   : SEC0015994608A6
10.11.12.105     : br0   : AP

IPv6:
2607:fa48:6e69:c410:50b7:53e0:b6f6:6f0c  : br0   : raspberrypi
2607:fa48:6e69:c410:ba27:ebff:fec5:1b3e  : br0   : AP
2607:fa48:6e69:c410:d6:6ff:fec0:d15f     : br0   : NAS1
pi@raspberrypi:~ $ 

jahboater
Posts: 4840
Joined: Wed Feb 04, 2015 6:38 pm

Re: Detect IP and MAC of headless PI

Tue Dec 22, 2015 9:03 am

Try something like:-

Code: Select all

sudo nmap -sn 192.168.0.0/24

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Detect IP and MAC of headless PI

Tue Dec 22, 2015 10:01 am

If you are on a network with tight security, ask permission first. nmap especially can be seen as an attack, and so can this...

The other way to do it, if you have an Android phone, is to run Fing on your phone. It scans the entire network and tells you the IP address of everything.

IIRC, Apple disabled the required functionality on iPhone.

I'll say again, be careful even having nmap installed if you don't own the network. You could find yourself having a very uncomfortable conversation with the network security officers. Fing is less intrusive but may set off alarms set to detect nmap because nmap can be used to find vulnerabilities to hack. (It's what Trinity uses in Matrix Reloaded.)

Return to “Troubleshooting”