istage
Posts: 9
Joined: Fri Jan 10, 2014 3:59 pm

how to detect a new joining device by PI?

Wed May 28, 2014 11:12 am

hi, i want to use pi for detecting new joined device ip or more info. as host name, but i have not idea how to do that? need a help.
thanks

broo0ose
Posts: 317
Joined: Wed Dec 14, 2011 3:59 pm
Location: Wirral, UK

Re: how to detect a new joining device by PI?

Wed May 28, 2014 9:32 pm

Are you in control of the network? You could turn off your current dhcp server and run a dhcp server from the Pi. Then you will know when a new device connects to the network.

Otherwise you would need cooperation with another device.

Or maybe a periodic ping sweep of the network.

User avatar
cyrano
Posts: 714
Joined: Wed Dec 05, 2012 11:48 pm
Location: Belgium

Re: how to detect a new joining device by PI?

Wed May 28, 2014 11:38 pm

Ping broadcast ip (x.x.x.255). Parse output.

Some devices might not respond to ping. There is no way to handle devices that want to hide from you...

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

Re: how to detect a new joining device by PI?

Thu May 29, 2014 7:58 am

cyrano wrote:Ping broadcast ip (x.x.x.255). Parse output.

Some devices might not respond to ping. There is no way to handle devices that want to hide from you...
ping -b x.x.x.255
doesn't work on my network, only my ADSL router (x.x.x.1) and the wireless AP (x.x.x.251) reply all other machines (including my RPis) don't respond to that broadcast ping.
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.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: how to detect a new joining device by PI?

Thu May 29, 2014 10:47 am

You could have a look at arpwatch, from what I remember last time I used it (a long time ago) it would at least tell you mac address and IP of new machines and when they change.

bullwinkle
Posts: 117
Joined: Wed Jan 09, 2013 12:14 pm

Re: how to detect a new joining device by PI?

Thu May 29, 2014 7:06 pm

There is a similar question over here:
http://www.raspberrypi.org/forums/viewt ... 86#p557286

I've made some notes about how I monitor new devices connection to my network. It is still experimental, so you'll need to check things out for yourself. There is room for improvement.
http://dumb-looks-free.blogspot.fr/2014 ... vices.html

good luck
Last edited by bullwinkle on Thu May 29, 2014 7:31 pm, edited 2 times in total.

User avatar
cyrano
Posts: 714
Joined: Wed Dec 05, 2012 11:48 pm
Location: Belgium

Re: how to detect a new joining device by PI?

Thu May 29, 2014 7:23 pm

DougieLawson wrote:
cyrano wrote:Ping broadcast ip (x.x.x.255). Parse output.

Some devices might not respond to ping. There is no way to handle devices that want to hide from you...
ping -b x.x.x.255
doesn't work on my network, only my ADSL router (x.x.x.1) and the wireless AP (x.x.x.251) reply all other machines (including my RPis) don't respond to that broadcast ping.
Thx Dougie, I always forget Raspberry doesn't support it. Why is there still no support for multicast?

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: how to detect a new joining device by PI?

Fri May 30, 2014 10:09 am

cyrano wrote:
DougieLawson wrote:
cyrano wrote:Ping broadcast ip (x.x.x.255). Parse output.

Some devices might not respond to ping. There is no way to handle devices that want to hide from you...
ping -b x.x.x.255
doesn't work on my network, only my ADSL router (x.x.x.1) and the wireless AP (x.x.x.251) reply all other machines (including my RPis) don't respond to that broadcast ping.
Thx Dougie, I always forget Raspberry doesn't support it. Why is there still no support for multicast?
Pinging x.x.x.255 (more accurately the last IP in an IPv4 subnet) isn't multicast that's broadcast and it's likely to be down to whether the other devices are configured to respond to broadcast pings.

Multicast is a different technology (using special class D addresses) and I have used it to stream video from a pi camera to various other devices successfully. You could try pinging the all-computers multicast group 224.0.0.1 although my tests seem to suggest that not many clients respond to that either (tested both from a Pi and from a Linux machine)

lb
Posts: 263
Joined: Sat Jan 28, 2012 8:07 pm

Re: how to detect a new joining device by PI?

Fri May 30, 2014 12:12 pm

IPv6 multicast works much more reliably than IPv4 broadcasts. You can enable IPv6 on your Pi and execute "ping6 ff02::1%eth0", all IPv6-capable devices on the network should answer.

Another option is to listen for zeroconf/mdns packets, but that of course also needs to be supported by the devices.

User avatar
davidevb6
Posts: 37
Joined: Wed Jul 24, 2013 3:22 pm

Re: how to detect a new joining device by PI?

Fri Jun 27, 2014 12:51 pm

Try this

Code: Select all

import httplib, urllib
import subprocess
import time
import urllib
import urllib2

#205 digital probe
#208 monitor TFT  server web
#86 PC windows
#202 rele
#211 analog Probe
#212 analog Probe wireless
#206 door windows probe
#207 door windows probe wireless

ip_device_list = [205,208,86,202,212,207]
ip_device_list_Error = []
while True:
    for ping in ip_device_list:
        print ip_device_list
        print ip_device_list_Error
        if (ping in ip_device_list_Error) == False:
            address = "192.168.0." + str(ping)
            res = subprocess.call(['ping', '-c', '1', address])
            if res == 0:
                print "ping to", address, "OK "
            else:
                print "no response from", address
                ip_device_list_Error.append(ping)
        else:
            address = "192.168.0." + str(ping)
            res = subprocess.call(['ping', '-c', '1', address])
            if res == 0:
                print "ping to", address, "OK "
                ip_device_list_Error.remove(ping)
            else:
                print "ping to", address, "failed!"
    time.sleep(300)

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: how to detect a new joining device by PI?

Mon Jun 30, 2014 12:15 am

That only looks for already-known IP addresses, but I guess the original question was about detecting new/unknown IP addresses.

User avatar
davidevb6
Posts: 37
Joined: Wed Jul 24, 2013 3:22 pm

Re: how to detect a new joining device by PI?

Mon Jun 30, 2014 6:14 am

Good spot!

change this

Code: Select all

ip_device_list = [205,208,86,202,212,207]
into this

Code: Select all

ip_device_list = range(1,255)   # 1,2,3....254

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: how to detect a new joining device by PI?

Mon Jun 30, 2014 9:30 am

davidevb6 wrote:Try this

Code: Select all

import httplib, urllib
import subprocess
import time
import urllib
import urllib2

#205 digital probe
#208 monitor TFT  server web
#86 PC windows
#202 rele
#211 analog Probe
#212 analog Probe wireless
#206 door windows probe
#207 door windows probe wireless

ip_device_list = [205,208,86,202,212,207]
ip_device_list_Error = []
while True:
    for ping in ip_device_list:
        print ip_device_list
        print ip_device_list_Error
        if (ping in ip_device_list_Error) == False:
            address = "192.168.0." + str(ping)
            res = subprocess.call(['ping', '-c', '1', address])
            if res == 0:
                print "ping to", address, "OK "
            else:
                print "no response from", address
                ip_device_list_Error.append(ping)
        else:
            address = "192.168.0." + str(ping)
            res = subprocess.call(['ping', '-c', '1', address])
            if res == 0:
                print "ping to", address, "OK "
                ip_device_list_Error.remove(ping)
            else:
                print "ping to", address, "failed!"
    time.sleep(300)
This also relies on the device responding to ping requests (not everything will).

I would highly recommend looking at the arpwatch program I mentioned in an earlier post (sudo apt-get install arpwatch)

This monitors ARP packets (required for IPv4 networks to work) and will send an email with IP and MAC addresses for new devices it sees on a network (it may also include hostnames but It's been a while since I've use it).

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

Re: how to detect a new joining device by PI?

Mon Jun 30, 2014 12:03 pm

mfa298 wrote: I would highly recommend looking at the arpwatch program I mentioned in an earlier post (sudo apt-get install arpwatch)
Interestingly arpwatch writes the arp data to /var/log/syslog (not /var/log/messages) on Raspbian, I thought it wasn't working.
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.

Return to “Advanced users”