Compare commits

...

2 Commits

Author SHA1 Message Date
df24780183 added 2024-10-07 16:53:56 +02:00
603eb6433c added 2024-10-07 16:53:17 +02:00
4 changed files with 88 additions and 11 deletions

View File

@@ -1,24 +1,64 @@
#! /usr/bin/env python3.12 #! /usr/bin/env python3.12
import subprocess import subprocess, os
def import_ssh_keys_to_agent(privat_key = str): def import_ssh_keys_to_agent(privat_key = str):
try: try:
run_add_key = subprocess.run( run_add_key = subprocess.run(
["/usr/bin/ssh-add", privat_key, '>>', "/dev/null"], [ "/usr/bin/ssh-add","-q", privat_key],
shell=False, shell=False,
text=False, text=False,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
timeout=1,) timeout=10,)
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
print("\n","Timeout, No Import :", privat_key)
return False return False
print(run_add_key) # print(run_add_key)
if run_add_key.returncode == 0: if run_add_key.returncode == 0:
return True return True
else: else:
return False return False
print(import_ssh_keys_to_agent(privat_key="/home/jonnybravo/.ssh/ansible-test")) def check_key_exist(ssh_pub=str):
if not os.path.exists(ssh_pub):
return False
run_check_key = subprocess.run(
[ "/usr/bin/ssh-add","-L"],
shell=False,
text=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,)
list_agent_pubs = str(run_check_key.stdout,encoding="utf-8").splitlines()
read_input_pub = open(ssh_pub)
READ_FILE_PUB = read_input_pub.read()
count=0
for pub in list_agent_pubs:
count = count +1
if READ_FILE_PUB == pub + "\n":
return True
return False
if __name__ == "__main__":
ssh_keys = [
"/home/jonnybravo/.ssh/ansible-test",
"/home/jonnybravo/.ssh/blu",
"/home/jonnybravo/.ssh/gitea",
"/home/jonnybravo/.ssh/gitlll",
]
for add_key in ssh_keys:
if not os.path.exists(add_key):
print("File", (add_key + ".pub"), "existiert nicht")
else:
if check_key_exist(ssh_pub=add_key + ".pub"):
print(add_key, "ist bereits vorhanden")
else:
print(add_key, "wird hinzugefügt...")
if import_ssh_keys_to_agent(privat_key=add_key):
print("Wurde hinzugefügt :", add_key)

View File

@@ -35,7 +35,7 @@ def create_ip_list(target_ip="192.168.50.1/24"):
only_ip_list.append(i['hostname']) only_ip_list.append(i['hostname'])
else: else:
only_ip_list.append(i['ip']) only_ip_list.append(i['ip'])
return only_ip_list return tuple(only_ip_list)
def scan_csv(csv_file=str): def scan_csv(csv_file=str):
pass pass
@@ -43,7 +43,7 @@ def scan_csv(csv_file=str):
if __name__ == "__main__": if __name__ == "__main__":
ip_list = create_ip_list() ip_list = create_ip_list()
man_list = ["ras-dan-01.local", "dan-jam-01"]
output = { output = {
"_meta": { "_meta": {
"hostvars": { "hostvars": {
@@ -52,8 +52,16 @@ if __name__ == "__main__":
} }
} }
}, },
"network-scan": { "network_scan": {
"hosts": ip_list, "hosts": ip_list,
"vars": {
"ansible_user": "jonnybravo",
"ansible_python_interpreter": "/usr/bin/python3",
"ansible_ssh_private_key_file": "/home/jonnybravo/.ssh/ansible-test"
}
},
"scan_csv": {
"hosts": man_list,
"vars":{ "vars":{
"ansible_user": "jonnybravo", "ansible_user": "jonnybravo",
"ansible_python_interpreter": "/usr/bin/python3", "ansible_python_interpreter": "/usr/bin/python3",
@@ -61,6 +69,5 @@ if __name__ == "__main__":
} }
} }
} }
print(json.dumps(output,indent=4, sort_keys=True)) print(json.dumps(output,indent=4, sort_keys=True))

16
play_with_os/scan_test.py Normal file
View File

@@ -0,0 +1,16 @@
#! /usr/bin/env Python3
# import OS module
import os
def scandir_recursive(directory):
scan_list = []
for entry in os.scandir(directory):
if entry.is_dir(follow_symlinks=False):
yield from scandir_recursive(entry.path)
else:
yield entry.path
scan_path = "/home/jonnybravo/Downloads"
for i in list(scandir_recursive(scan_path)):
print(i)

14
scapy_sniff/sniff.py Normal file
View File

@@ -0,0 +1,14 @@
#! /usr/bin/env python3
from scapy.all import sniff, wrpcap, rdpcap
#pakete = sniff(iface="wg0", count=10, filter="ip src 10.50.0.3", prn=lambda x:x.summary())
#pakete = sniff(iface="wg0", filter="host 10.50.0.3", prn=lambda x:x.show())
pakete = sniff(iface="wg0", filter="ip src 10.50.0.3", prn=lambda x:x.show())
#wrpcap("netscan.pcap", pakete)
#pakete.nsummary()
#for pkt in pakete:
# pkt.show()
# pkt.summary()