Initialer Import der Synology Scripts
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
---
|
||||
- name: Netzwerk Ping Scan und CSV Export
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
|
||||
vars:
|
||||
netzwerke:
|
||||
- "192.168.1.0/24"
|
||||
- "9.99.0.0/24"
|
||||
- "9.99.10.0/24"
|
||||
- "9.99.20.0/24"
|
||||
- "9.99.30.0/24"
|
||||
- "9.99.40.0/24"
|
||||
- "9.99.50.0/24"
|
||||
- "9.99.60.0/24"
|
||||
- "9.99.70.0/24"
|
||||
|
||||
csv_datei: "/mnt/scripte/NETWORK-SCAN/netzwerk_scan.csv"
|
||||
|
||||
tasks:
|
||||
|
||||
- name: Prüfen ob nmap installiert ist
|
||||
ansible.builtin.command:
|
||||
cmd: which nmap
|
||||
register: nmap_check
|
||||
failed_when: nmap_check.rc != 0
|
||||
|
||||
- name: Netzwerkbereiche scannen
|
||||
ansible.builtin.command:
|
||||
cmd: "nmap -sn {{ item }}"
|
||||
loop: "{{ netzwerke }}"
|
||||
register: scan_ergebnis
|
||||
|
||||
- name: Scan-Ergebnisse zusammenführen
|
||||
ansible.builtin.set_fact:
|
||||
scan_text: "{{ scan_ergebnis.results | map(attribute='stdout') | join('\n') }}"
|
||||
|
||||
- name: CSV Datei erzeugen
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ csv_datei }}"
|
||||
content: |
|
||||
IP-Adresse,Status
|
||||
{% for line in scan_text.split('\n') %}
|
||||
{% if 'Nmap scan report for' in line %}
|
||||
{{ line | regex_replace('.*for ', '') }},ONLINE
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
- name: Ergebnis anzeigen
|
||||
ansible.builtin.debug:
|
||||
msg: "Scan abgeschlossen. Datei: {{ csv_datei }}"
|
||||
Reference in New Issue
Block a user