How to find all Red Pitaya devices on the local network?

Just about everything about Red Pitaya
Post Reply
lene85
Posts: 23
Joined: Tue Sep 08, 2015 3:04 pm

How to find all Red Pitaya devices on the local network?

Post by lene85 » Thu Jul 06, 2017 9:35 am

For my project PyRPL (https://www.github.com/lneuhaus/pyrpl), I would like to offer the user to select any of the Red Pitaya devices on the local network to work with. At the moment, the best solution I can think of is to scan the local network (a la https://stackoverflow.com/questions/136 ... al-network) for all available hosts. Then I would attempt an ssh connection to all hosts with user=root, password=root, and somehow try to identify whether the device is a Red Pitaya. For example, this could be done by testing whether the MAC address starts with the characters 00:26:32:

Code: Select all

ifconfig | grep HWaddr
> eth0      Link encap:Ethernet  HWaddr 00:26:32:F0:3E:A0
This is a very error-prone business I think, especially because I dont really know what the right ip addresses to try for are in a general setting.

Does anyone have a better solution in mind?

izi
Posts: 34
Joined: Wed May 27, 2015 11:49 am

Re: How to find all Red Pitaya devices on the local network?

Post by izi » Fri Jul 07, 2017 3:03 pm

Red Pitaya advertises its presence using Avahi.
https://github.com/RedPitaya/RedPitaya/ ... i/services

You could use a tool like avahi-browse to list your devices:
https://linux.die.net/man/1/avahi-browse
https://linux.die.net/man/1/avahi-discover

lene85
Posts: 23
Joined: Tue Sep 08, 2015 3:04 pm

Re: How to find all Red Pitaya devices on the local network?

Post by lene85 » Fri Jul 07, 2017 6:00 pm

Sounds cool. Do you know by any chance whether this is OS-dependent, i.e. whether this feature was already present in version 0.92 or the Redpitaya ecosystem? Thanks!

amike88
Posts: 89
Joined: Tue Mar 29, 2016 7:41 pm

Re: How to find all Red Pitaya devices on the local network?

Post by amike88 » Wed Jul 12, 2017 11:24 am

Indeed it is OS-dependent, this feature was added to the OS version 0.96.

lene85
Posts: 23
Joined: Tue Sep 08, 2015 3:04 pm

Re: How to find all Red Pitaya devices on the local network?

Post by lene85 » Thu Jul 13, 2017 12:13 pm

Thanks. For info, in the meantime I implemented a brute-force solution (https://github.com/lneuhaus/pyrpl/issues/305) that scans the LAN for devices with open SSH-port, attempts to connect with standard username (root) and password (root), and then verifies if the devices' MAC address is starts with the first 6 digits of all redpitaya mac addresses. Depending on timeout settings, this procedure completes within 1-10 seconds and has so far never missed a redpitaya on various networks. For your info, I am posting the (uncleaned and pyrpl-dependent) Python-code below.

Code: Select all

import socket
import pyrpl
port = 22
timeout=0.01
from time import sleep
def get_ip():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        # doesn't even have to be reachable
        s.connect(('10.255.255.255', 1))
        IP = s.getsockname()[0]
    except:
        IP = '127.0.0.1'
    finally:
        s.close()
    return IP
ip=get_ip()
print ("Your own ip is: %s"%ip)
end=ip.split('.')[-1]
start = ip[:-len(end)]
ips = [start+str(i) for i in range(256)]
sockets = []
for ip in ips:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(timeout)
    #s.setblocking(1)
    err = s.connect_ex((ip, port))
    if err == 0:
        #print ("%s:%d is open"%(ip, port))
        s.close()
        try:
            ssh = pyrpl.sshshell.SSHshell(hostname=ip, timeout=1)
        except BaseException as e: 
            print 'Cannot log in with user=root, pw=root at', ip
        else:
            #print "root pw works"
            macs = list()
            nextgood = False
            for token in ssh.ask('ifconfig | grep HWaddr').split():
                  if nextgood and len(token.split(':')):
                      if token.startswith('00:26:32:'):
                          macs.append(token)
                          print 'RP device: ', ip, token
                  if token == 'HWaddr':
                      nextgood = True
                  else:
                      nextgood = False
            #print(macs)
            ssh.channel.close()
    else:
        s.close()
print ('done')
Output:
Your own ip is: 10.214.1.43
Cannot log in with user=root, pw=root at 10.214.1.8
RP device: 10.214.1.9 00:26:32:F0:08:8A
RP device: 10.214.1.15 00:26:32:F0:0C:86
RP device: 10.214.1.20 00:26:32:F0:0E:49
Cannot log in with user=root, pw=root at 10.214.1.254
done

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 5 guests