Page 1 of 1
How to find all Red Pitaya devices on the local network?
Posted: Thu Jul 06, 2017 9:35 am
by lene85
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?
Re: How to find all Red Pitaya devices on the local network?
Posted: Fri Jul 07, 2017 3:03 pm
by izi
Re: How to find all Red Pitaya devices on the local network?
Posted: Fri Jul 07, 2017 6:00 pm
by lene85
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!
Re: How to find all Red Pitaya devices on the local network?
Posted: Wed Jul 12, 2017 11:24 am
by amike88
Indeed it is OS-dependent, this feature was added to the OS version 0.96.
Re: How to find all Red Pitaya devices on the local network?
Posted: Thu Jul 13, 2017 12:13 pm
by lene85
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