Code: Select all
ifconfig | grep HWaddr
> eth0 Link encap:Ethernet HWaddr 00:26:32:F0:3E:A0
Does anyone have a better solution in mind?
Code: Select all
ifconfig | grep HWaddr
> eth0 Link encap:Ethernet HWaddr 00:26:32:F0:3E:A0
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')
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
Users browsing this forum: No registered users and 107 guests