On Wed, 18 May 2022 23:52:05 +0200, ^Bart wrote: > Hi guys, > > i need to copy some files from a Debian client to all linux embedded > clients. > > I know the linux commands like: > > # scp "my_file" root@192.168.205.x/my_directory > > But... I have to upload 100 devices, I have a lan and a dhcp server just > for this work and I'd like to make a script by Python which can: > > 1) To scan the lan 2) To find which ips are "ready" > 3) To send files to all of the "ready" clients 4) After I see on the > display of these clients the successfully update I remove from the lan > them and I put them to the box to send them to our customers. > > I found https://pypi.org/project/python-nmap/ and I followed the line > "To check the network status" but... it doesn't work. > > THE INPUT > ------------------------------------------------------------------------- > import nmap nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE > -PA21,23,80,3389') > hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()] > for host, status in hosts_list: > print('{0}:{1}'.host) > > THE OUTPUT > --------------------------------------------------------------------- > Traceback (most recent call last): > File "/home/gabriele/Documenti/Python/nmap.py", line 1, in <module> > import nmap > File "/home/gabriele/Documenti/Python/nmap.py", line 2, in <module> > nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE > -PA21,23,80,3389') > NameError: name 'nm' is not defined > > Regards. > ^Bart
Opbservations worth considering 1) could possibly be handled by a simple bash script (My bash skills are not great So i would probably still go python myself anyway) 2) Instead of checking availability just try to send & react appropriately if it fails (Ask for forgiveness not permission), the client could fail after test or during transfer anyway so you will still need this level of error checking -- QOTD: "What women and psychologists call `dropping your armor', we call "baring your neck." -- https://mail.python.org/mailman/listinfo/python-list