modify
This commit is contained in:
24
SSH_Agent/main.py
Normal file
24
SSH_Agent/main.py
Normal file
@@ -0,0 +1,24 @@
|
||||
#! /usr/bin/env python3.12
|
||||
import subprocess
|
||||
|
||||
def import_ssh_keys_to_agent(privat_key = str):
|
||||
try:
|
||||
run_add_key = subprocess.run(
|
||||
["/usr/bin/ssh-add", privat_key, '>>', "/dev/null"],
|
||||
shell=False,
|
||||
text=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
timeout=1,)
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
return False
|
||||
|
||||
print(run_add_key)
|
||||
if run_add_key.returncode == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
print(import_ssh_keys_to_agent(privat_key="/home/jonnybravo/.ssh/ansible-test"))
|
||||
14
play_ansible/inv_plugin/ansible.cfg
Executable file
14
play_ansible/inv_plugin/ansible.cfg
Executable file
@@ -0,0 +1,14 @@
|
||||
[defaults]
|
||||
|
||||
#inventory = /home/user06/hosts
|
||||
inventory = ./test.py
|
||||
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S on {host}
|
||||
private_key_file = /home/jonnybravo/.ssh/ansible-test
|
||||
gathering = smart
|
||||
fact_caching = yaml
|
||||
fact_caching_timeout = 3600
|
||||
fact_caching_connection = fact
|
||||
library = lib
|
||||
lookup_plugins = lookup
|
||||
|
||||
filter_plugins = ./filter
|
||||
66
play_ansible/inv_plugin/test.py
Executable file
66
play_ansible/inv_plugin/test.py
Executable file
@@ -0,0 +1,66 @@
|
||||
#! /usr/bin/env python3.12
|
||||
|
||||
import scapy.all as scapy
|
||||
import json
|
||||
import socket
|
||||
|
||||
def scan(ip):
|
||||
arp_request = scapy.ARP(pdst=ip)
|
||||
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
|
||||
arp_request_broadcast = broadcast / arp_request
|
||||
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
|
||||
results = []
|
||||
for element in answered_list:
|
||||
result = {"ip": element[1].psrc, "mac": element[1].hwsrc, 'hostname': socket.gethostbyaddr(element[1].psrc)[0]}
|
||||
results.append(result)
|
||||
return results
|
||||
|
||||
|
||||
def test_port(address: str, dest_port: int) -> bool:
|
||||
try:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
if sock.connect_ex((address, dest_port)) == 0:
|
||||
return True
|
||||
return False
|
||||
except (OSError, ValueError):
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def create_ip_list(target_ip="192.168.50.1/24"):
|
||||
only_ip_list = []
|
||||
for i in scan(target_ip):
|
||||
#print(test_port(address=i['ip'], dest_port=22))
|
||||
if i['hostname'] != ".":
|
||||
only_ip_list.append(i['hostname'])
|
||||
else:
|
||||
only_ip_list.append(i['ip'])
|
||||
return only_ip_list
|
||||
|
||||
def scan_csv(csv_file=str):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ip_list = create_ip_list()
|
||||
|
||||
output = {
|
||||
"_meta": {
|
||||
"hostvars": {
|
||||
"webprod": {
|
||||
"http_port": 123,
|
||||
}
|
||||
}
|
||||
},
|
||||
"network-scan": {
|
||||
"hosts": ip_list,
|
||||
"vars": {
|
||||
"ansible_user": "jonnybravo",
|
||||
"ansible_python_interpreter": "/usr/bin/python3",
|
||||
"ansible_ssh_private_key_file": "/home/jonnybravo/.ssh/ansible-test"
|
||||
}
|
||||
}
|
||||
}
|
||||
print(json.dumps(output,indent=4, sort_keys=True))
|
||||
|
||||
|
||||
@@ -1,35 +1,43 @@
|
||||
#! /usr/bin/env python3.10
|
||||
|
||||
#! /usr/bin/env python3
|
||||
import os
|
||||
|
||||
def show_all_files_directory(dir_path = str, search_endung = False, search_string = False):
|
||||
li_all = []
|
||||
for root_folder, dirs, files in os.walk(dir_path, topdown=False):
|
||||
for (root_folder, dirs, files) in os.walk(dir_path, topdown=False):
|
||||
for name in files:
|
||||
FullPATH = str(os.path.join(root_folder, name))
|
||||
FullPATH = [str(os.path.join(root_folder, name)), name]
|
||||
|
||||
if not search_endung is False:
|
||||
if FullPATH.endswith(search_endung):
|
||||
li_all.append(FullPATH)
|
||||
li_all.append(FullPATH)
|
||||
elif not search_string is False:
|
||||
if not FullPATH.find(search_string) == -1:
|
||||
li_all.append(FullPATH)
|
||||
else:
|
||||
li_all.append(FullPATH)
|
||||
return li_all
|
||||
|
||||
|
||||
|
||||
def main(check_list = list, main_folder_in = str):
|
||||
output_list = []
|
||||
for folder_name in check_list:
|
||||
main_folder =main_folder_in + os.sep + folder_name
|
||||
if os.path.exists(main_folder):
|
||||
run_file_check = show_all_files_directory(dir_path=main_folder)
|
||||
for file_name in run_file_check:
|
||||
output_list.append(str(folder_name + '=' +file_name[1]))
|
||||
else:
|
||||
print(main_folder, "existiert nicht")
|
||||
return output_list
|
||||
|
||||
|
||||
|
||||
# print(os.get_exec_path())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
# test = show_all_files_directory(dir_path=os.sep + "home" + os.sep + "jonnybravo" + os.sep + "Downloads", search_string="linux")
|
||||
# for i in test:
|
||||
# print(i)
|
||||
print(os.get_exec_path())
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
check_folders = ["Downloads", "Dokumente", "diokdkij"]
|
||||
running_main = main(check_list=check_folders, main_folder_in=os.sep + "home" + os.sep + "jonnybravo")
|
||||
for run in running_main:
|
||||
with open("output_file", "a") as file:
|
||||
print(run, file=file)
|
||||
Reference in New Issue
Block a user