Re: Python & nmap
Lars Liedtke writes: > Ansible has got a shell module, so you could run custom commands on all > hosts. But it gets more difficult in parsing the output afterwards. If you just want to copy files, pdsh[1] or clush[2] might be enough. Cheers, Loris Footnotes: [1] https://github.com/chaos/pdsh [2] https://clustershell.readthedocs.io/en/latest/tools/clush.html -- This signature is currently under construction. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python & nmap
Ansible has got a shell module, so you could run custom commands on all hosts. But it gets more difficult in parsing the output afterwards. -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 19.05.22 um 21:16 schrieb ^Bart: Maybe it could be a good idea to look at Ansible for copying the Files to all the hosts, because that is one thing ansible is made for. I didn't know it... thanks to share it but... I should start to study it and I don't have not enought free time... but maybe in the future I'll do it! :) For the nmap part: Ansible does not have a module for that (sadly) but is very extensible, so if you start developing something like that in Python, you could as well write an ansible module and combine both, because Ansible itself is written in Python. Ah ok, maybe now I just start to write a bash script because I need to start this work asap, when I'll have one minute I'll try to move the script in Python and after it I could "upload" the work on Ansible! :) Cheers Lars Thanks! ^Bart -- https://mail.python.org/mailman/listinfo/python-list
Re: Python & nmap
On 2022-05-19 20:28, ^Bart wrote: You forgot the second line (after 'import nmap' and before 'nm.scan()'): nm = nmap.PortScanner() import nmap nm = nmap.PortScanner() 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) And the result is: Traceback (most recent call last): File "/home/gabriele/Documenti/Python/nmap.py", line 1, in import nmap File "/home/gabriele/Documenti/Python/nmap.py", line 2, in nm = nmap.PortScanner() AttributeError: partially initialized module 'nmap' has no attribute 'PortScanner' (most likely due to a circular import) >>> I'm using the IDLE Shell 3.9.2 on Debian Bullseye+KDE, if I write the script from command line it works! When you installed nmap it would've been installed into site-packages, but the traceback says "/home/gabriele/Documenti/Python/nmap.py", which suggests to me that you called your script "nmap.py", so it's shadowing what you installed and is actually trying to import itself! -- https://mail.python.org/mailman/listinfo/python-list
Re: Python & nmap
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) Like what I wrote in my last reply to another user now I need to start this work asap so maybe I'll start to write a rough bash script and I hope to manage it when I'll have free time on Python! 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 Sadly true... I didn't think about it but maybe I could find a solution in bash script... Thanks for your reply! :) ^Bart -- https://mail.python.org/mailman/listinfo/python-list
Re: Python & nmap
You forgot the second line (after 'import nmap' and before 'nm.scan()'): nm = nmap.PortScanner() import nmap nm = nmap.PortScanner() 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) And the result is: Traceback (most recent call last): File "/home/gabriele/Documenti/Python/nmap.py", line 1, in import nmap File "/home/gabriele/Documenti/Python/nmap.py", line 2, in nm = nmap.PortScanner() AttributeError: partially initialized module 'nmap' has no attribute 'PortScanner' (most likely due to a circular import) >>> I'm using the IDLE Shell 3.9.2 on Debian Bullseye+KDE, if I write the script from command line it works! ^Bart -- https://mail.python.org/mailman/listinfo/python-list
Re: Python & nmap
Maybe it could be a good idea to look at Ansible for copying the Files to all the hosts, because that is one thing ansible is made for. I didn't know it... thanks to share it but... I should start to study it and I don't have not enought free time... but maybe in the future I'll do it! :) For the nmap part: Ansible does not have a module for that (sadly) but is very extensible, so if you start developing something like that in Python, you could as well write an ansible module and combine both, because Ansible itself is written in Python. Ah ok, maybe now I just start to write a bash script because I need to start this work asap, when I'll have one minute I'll try to move the script in Python and after it I could "upload" the work on Ansible! :) Cheers Lars Thanks! ^Bart -- https://mail.python.org/mailman/listinfo/python-list
Re: Python & nmap
# scp "my_file" root@192.168.205.x/my_directory Maybe it could be a good idea to look at Ansible for copying the Files to all the hosts, because that is one thing ansible is made for. For the nmap part: Ansible does not have a module for that (sadly) but is very extensible, so if you start developing something like that in Python, you could as well write an ansible module and combine both, because Ansible itself is written in Python. Cheers Lars -- Lars Liedtke Software Entwickler Phone: Fax:+49 721 98993- E-mail: l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany Marken der solute GmbH | brands of solute GmbH billiger.de | Shopping.de Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php -- https://mail.python.org/mailman/listinfo/python-list
Re: Python & nmap
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 > import nmap >File "/home/gabriele/Documenti/Python/nmap.py", line 2, in > 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
Re: Python & nmap
On 2022-05-18, ^Bart wrote: > 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 > import nmap >File "/home/gabriele/Documenti/Python/nmap.py", line 2, in > nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE > -PA21,23,80,3389') > NameError: name 'nm' is not defined You forgot the second line (after 'import nmap' and before 'nm.scan()'): nm = nmap.PortScanner() -- https://mail.python.org/mailman/listinfo/python-list
Python & nmap
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 import nmap File "/home/gabriele/Documenti/Python/nmap.py", line 2, in nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE -PA21,23,80,3389') NameError: name 'nm' is not defined Regards. ^Bart -- https://mail.python.org/mailman/listinfo/python-list
Re: python nmap for loop
> I'm trying to make the following code work: > ... It seems fairly clear that you've posted code which couldn't possibly run (missing a closing quote and right paren). Let me suggest: 1. You copy and paste directly from a Python (or IPython/Jupyter/IDLE) session, including prompts and output. 2. You tell us what you expected to happen, and what actually happened. Skip -- https://mail.python.org/mailman/listinfo/python-list
python nmap for loop
I'm trying to make the following code work: import os, sys app=['host1', 'host2', 'host3'] for i in app: os.system('nmap -p 22 -P0 %s | grep open 2>&1 > /dev/null && echo "%s up" I've tried many different iterations of the os.system call, how to make this work? TIA -- https://mail.python.org/mailman/listinfo/python-list
Python Nmap script linux version
I made this script for fun. you need to have Nmap installed on your linux computer and it will find all the computers on the network and then run Nmap on it. Hope you enjoy! import os fn = 'i.result' ip = '192.168.1.1-255' ip1 = ip[:3] ips = [] os.system("nmap -sP 192.168.1.1-255 > "+fn) f = open(fn) try: for line in f: if ip1 in line: ips.append(line[5:-19]) finally: f.close() os.system("clear") for i in ips: print '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' os.system("nmap "+i) print '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' raw_input('press to continue...') Tell me what you think -- http://mail.python.org/mailman/listinfo/python-list
Python Nmap Scour sP script for linux
I made this script for fun. you need to have Nmap installed on your linux computer and it will find all the computers on the network and then run Nmap on it. Hope you enjoy! import os fn = 'i.result' ip = '192.168.1.1-255' ip1 = ip[:3] ips = [] os.system("nmap -sP 192.168.1.1-255 > "+fn) f = open(fn) try: for line in f: if ip1 in line: ips.append(line[5:-19]) finally: f.close() os.system("clear") for i in ips: print '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' os.system("nmap "+i) print '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' raw_input('press to continue...') -- http://mail.python.org/mailman/listinfo/python-list