all
This commit is contained in:
2
SSH_Agent/main.py
Normal file → Executable file
2
SSH_Agent/main.py
Normal file → Executable file
@@ -49,7 +49,7 @@ if __name__ == "__main__":
|
|||||||
"/home/jonnybravo/.ssh/ansible-test",
|
"/home/jonnybravo/.ssh/ansible-test",
|
||||||
"/home/jonnybravo/.ssh/blu",
|
"/home/jonnybravo/.ssh/blu",
|
||||||
"/home/jonnybravo/.ssh/gitea",
|
"/home/jonnybravo/.ssh/gitea",
|
||||||
"/home/jonnybravo/.ssh/gitlll",
|
"/home/jonnybravo/.ssh/gitlab_ed25519",
|
||||||
]
|
]
|
||||||
|
|
||||||
for add_key in ssh_keys:
|
for add_key in ssh_keys:
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
import os, sys, subprocess
|
import os, sys, subprocess
|
||||||
|
|
||||||
class nfs_server_conf:
|
class nfs_server_conf:
|
||||||
|
"""
|
||||||
|
Diese Class installiert nur einen NFS Server mit Systemd voraussetzung ist das nsfv4 installiert ist
|
||||||
|
"""
|
||||||
def __init__(self, nfs_srv_folders = ["/nfsroot/publicnfs","/nfsroot/datennfs"], nfs_config_file = "/etc/exports", allow_network = "192.168.50.0/25") -> None:
|
def __init__(self, nfs_srv_folders = ["/nfsroot/publicnfs","/nfsroot/datennfs"], nfs_config_file = "/etc/exports", allow_network = "192.168.50.0/25") -> None:
|
||||||
if not os.geteuid()==0:
|
if not os.geteuid()==0:
|
||||||
raise PermissionError("Sie sind kein Root")
|
raise PermissionError("Sie sind kein Root")
|
||||||
@@ -95,4 +98,4 @@ class nfs_server_conf:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
my_nfs_server = nfs_server_conf(allow_network="*")
|
my_nfs_server = nfs_server_conf(allow_network="*")
|
||||||
my_nfs_server.main_install()
|
my_nfs_server.main_install()
|
||||||
|
|||||||
75
install_nfsv4_share/nfs_server_v2_ollama.py
Normal file
75
install_nfsv4_share/nfs_server_v2_ollama.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import os
|
||||||
|
import systemd.daemon
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
class NFSServerConf:
|
||||||
|
def __init__(self, nfs_srv_folders: List[str] = ["/nfsroot/publicnfs", "/nfsroot/datennfs"],
|
||||||
|
nfs_config_file: str = "/etc/exports", allow_network: str = "192.168.50.0/25"):
|
||||||
|
self._validate_input(nfs_srv_folders)
|
||||||
|
self._validate_input(nfs_config_file)
|
||||||
|
|
||||||
|
self.nfs_srv_folders = nfs_srv_folders
|
||||||
|
self.nfs_config_file = nfs_config_file
|
||||||
|
self.allow_network = allow_network
|
||||||
|
|
||||||
|
def _validate_input(self, input_value: str) -> None:
|
||||||
|
if not isinstance(input_value, str):
|
||||||
|
raise ValueError(f"Input muss eine Zeichenkette sein. ({type(input_value).__name__} wurde verwendet.)")
|
||||||
|
if not os.path.exists(input_value):
|
||||||
|
raise ValueError(f"Datei {input_value} existiert nicht.")
|
||||||
|
|
||||||
|
def mount_serverfolder(self) -> None:
|
||||||
|
# Durchsuche das angegebene Verzeichnis und seine Unterordner nach Dateien und erstelle eine Liste von Dateipfaden
|
||||||
|
server_folder_list = []
|
||||||
|
for folder in self.nfs_srv_folders:
|
||||||
|
files_in_folder = [os.path.join(folder, file) for file in os.listdir(folder)]
|
||||||
|
server_folder_list.extend(files_in_folder)
|
||||||
|
|
||||||
|
# Erstelle für jedes Verzeichnis in nfs_srv_folders ein Unit-File im Format .mount in /etc/systemd/system/
|
||||||
|
for folder in self.nfs_srv_folders:
|
||||||
|
mount_unit_file = f"/etc/systemd/system/{os.path.basename(folder)}.mount"
|
||||||
|
with open(mount_unit_file, "w") as file:
|
||||||
|
file.write("[Unit]\n")
|
||||||
|
file.write(f"Description=Mount {folder}\n")
|
||||||
|
file.write("[Mount]\n")
|
||||||
|
file.write(f"Where={folder}\n")
|
||||||
|
file.write("What=/mnt/nfs\n")
|
||||||
|
|
||||||
|
# Starte und ermögliche den Dienst für jedes Unit-File
|
||||||
|
systemd.daemon.notify(systemd.daemon.DaemonReload)
|
||||||
|
|
||||||
|
def nfs_server_conf(self) -> None:
|
||||||
|
# Durchsuche die Konfiguration des NFS-Servers (im Standardfall /etc/exports) nach Verzeichnissen
|
||||||
|
with open(self.nfs_config_file, "r") as file:
|
||||||
|
config_content = file.readlines()
|
||||||
|
|
||||||
|
# Zähle, wie oft jeder Verzeichnis-Pfad in der Konfiguration vorkommt
|
||||||
|
folder_count = {}
|
||||||
|
for line in config_content:
|
||||||
|
if ":" in line and not line.startswith("#"):
|
||||||
|
folder_path = line.split(":")[0].strip()
|
||||||
|
if folder_path not in folder_count:
|
||||||
|
folder_count[folder_path] = 1
|
||||||
|
else:
|
||||||
|
folder_count[folder_path] += 1
|
||||||
|
|
||||||
|
# Füge für jeden Verzeichnis-Pfad hinzu, der nicht bereits in der Konfiguration vorhanden ist, einen neuen Eintrag in die Konfiguration
|
||||||
|
for folder in self.nfs_srv_folders:
|
||||||
|
if folder not in [line.strip() for line in config_content]:
|
||||||
|
with open(self.nfs_config_file, "a") as file:
|
||||||
|
file.write(f"{folder}({self.allow_network})\n")
|
||||||
|
|
||||||
|
def start_nfs_server(self) -> None:
|
||||||
|
# Starte und ermögliche den Dienst für den NFS-Server (im Standardfall nfsv4-server.service)
|
||||||
|
systemd.daemon.notify(systemd.daemon.DaemonReload)
|
||||||
|
|
||||||
|
|
||||||
|
def main_install():
|
||||||
|
nfsserverconf = NFSServerConf()
|
||||||
|
nfsserverconf.mount_serverfolder()
|
||||||
|
nfsserverconf.nfs_server_conf()
|
||||||
|
nfsserverconf.start_nfs_server()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_install()
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
[defaults]
|
[defaults]
|
||||||
|
|
||||||
#inventory = /home/user06/hosts
|
#inventory = /home/user06/hosts
|
||||||
inventory = ./test.py
|
inventory = ./main.py
|
||||||
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S on {host}
|
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S on {host}
|
||||||
private_key_file = /home/jonnybravo/.ssh/ansible-test
|
private_key_file = /home/jonnybravo/.ssh/ansible-test
|
||||||
gathering = smart
|
gathering = smart
|
||||||
|
|||||||
93
play_ansible/inv_plugin/ansible_inv_main.py
Executable file
93
play_ansible/inv_plugin/ansible_inv_main.py
Executable file
@@ -0,0 +1,93 @@
|
|||||||
|
#! /usr/bin/env python3.12
|
||||||
|
|
||||||
|
import scapy.all as scapy
|
||||||
|
import json, socket, csv, os, errno, sys
|
||||||
|
|
||||||
|
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 port_open(address: str, dest_port=22) -> bool:
|
||||||
|
#result = sock.connect_ex(('ras-dan-01.local',22))
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||||
|
sock.settimeout(5)
|
||||||
|
result = sock.connect_ex((address,dest_port))
|
||||||
|
if result == 0:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def scan_csv(csvfile=str, colm="hostname"):
|
||||||
|
if os.path.exists(csvfile):
|
||||||
|
hostlist = []
|
||||||
|
with open(csvfile) as csv_file:
|
||||||
|
csv_reader = csv.DictReader(csv_file, delimiter=',')
|
||||||
|
for count, row in enumerate(csv_reader, 1):
|
||||||
|
hostlist.append(row[colm])
|
||||||
|
else:
|
||||||
|
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), csvfile)
|
||||||
|
return tuple(hostlist)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def create_ip_list(target_ip=["192.168.50.1/24"]):
|
||||||
|
only_ip_list = []
|
||||||
|
for ip_rage in target_ip:
|
||||||
|
for i in scan(ip_rage):
|
||||||
|
if i['hostname'] != ".":
|
||||||
|
scan_name = (i['hostname'])
|
||||||
|
else:
|
||||||
|
scan_name = (i['ip'])
|
||||||
|
|
||||||
|
#print(scan_name)
|
||||||
|
#print(port_open(address=scan_name))
|
||||||
|
if port_open(address=scan_name):
|
||||||
|
only_ip_list.append(scan_name)
|
||||||
|
|
||||||
|
return tuple(only_ip_list)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
#if len(sys.argv) == 1:
|
||||||
|
ip_list = create_ip_list()
|
||||||
|
man_list = scan_csv(csvfile="hostname_manuel.csv")
|
||||||
|
output = {
|
||||||
|
"_meta": {
|
||||||
|
"hostvars": {
|
||||||
|
"scan_csv": {
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"csv_scan": {
|
||||||
|
"hosts": man_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))
|
||||||
|
# elif len(sys.argv) == 2:
|
||||||
|
# print(sys.argv)
|
||||||
3
play_ansible/inv_plugin/hostname_manuel.csv
Normal file
3
play_ansible/inv_plugin/hostname_manuel.csv
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
hostname, info
|
||||||
|
dan-jam-01, keine,
|
||||||
|
ras-dan-01.local, keine,
|
||||||
|
@@ -1,73 +0,0 @@
|
|||||||
#! /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 tuple(only_ip_list)
|
|
||||||
|
|
||||||
def scan_csv(csv_file=str):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
ip_list = create_ip_list()
|
|
||||||
man_list = ["ras-dan-01.local", "dan-jam-01"]
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"scan_csv": {
|
|
||||||
"hosts": man_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,20 +1,48 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
def show_all_files_directory(dir_path = str, search_endung = False, search_string = False):
|
def show_all_files_directory(dir_path: str, search_endung: str = None, search_string: str = None) -> list:
|
||||||
li_all = []
|
"""
|
||||||
|
Returns a list of all files in the directory and its subdirectories.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
dir_path (str): Path to the root directory.
|
||||||
|
search_endung (str): Ending for the file names to be searched. Default is None.
|
||||||
|
search_string (str): String to be searched in the file names. Default is None.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: List of full paths to all files matching the search criteria.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Check if dir_path is not empty and exists
|
||||||
|
if not os.path.isdir(dir_path):
|
||||||
|
print("Die angegebene Verzeichnispfad existiert nicht.")
|
||||||
|
return []
|
||||||
|
|
||||||
|
all_files_path = []
|
||||||
|
|
||||||
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:
|
for name in files:
|
||||||
FullPATH = str(os.path.join(root_folder, name))
|
full_path = str(os.path.join(root_folder, name))
|
||||||
if not search_endung is False:
|
|
||||||
if FullPATH.endswith(search_endung):
|
# If search_endung is specified
|
||||||
li_all.append(FullPATH)
|
if search_endung:
|
||||||
elif not search_string is False:
|
if not full_path.endswith(search_endung):
|
||||||
if not FullPATH.find(search_string) == -1:
|
continue
|
||||||
li_all.append(FullPATH)
|
|
||||||
else:
|
# If search_string is specified
|
||||||
li_all.append(FullPATH)
|
elif search_string:
|
||||||
return li_all
|
if full_path.find(search_string) == -1:
|
||||||
|
continue
|
||||||
|
|
||||||
|
all_files_path.append(full_path)
|
||||||
|
|
||||||
|
print("Dateien:")
|
||||||
|
for file in all_files_path:
|
||||||
|
print(file)
|
||||||
|
|
||||||
print(show_all_files_directory(dir_path="/home/jonnybravo/Downloads", search_string=".txt"))
|
return all_files_path
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test = show_all_files_directory(dir_path="/home/jonnybravo/Downloads", search_endung=".txt")
|
||||||
|
print(test)
|
||||||
51
steam.py
Normal file
51
steam.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
# Steam-API-Einheitspunkt
|
||||||
|
STEAM_API_URL = "https://api.steampowered.com"
|
||||||
|
|
||||||
|
# Benutzer-ID oder Anwendung-ID
|
||||||
|
USER_ID = "656119799984" # ersetzen Sie mit der ID des Benutzers oder der Anwendung, für die Sie Informationen benötigen
|
||||||
|
|
||||||
|
def get_user_info(user_id):
|
||||||
|
"""
|
||||||
|
Ruft die Information über einen bestimmten Benutzer ab.
|
||||||
|
"""
|
||||||
|
url = f"{STEAM_API_URL}/ISteamUser/GetPlayerSummarInfo/v0001/?key=80BED3ACB9E38E5A944F2BEB26FC9C3E&steamids={user_id}"
|
||||||
|
response = requests.get(url)
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.text
|
||||||
|
return data
|
||||||
|
else:
|
||||||
|
print(f"Ein Fehler auftrat: {response.status_code}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_app_info(app_id):
|
||||||
|
"""
|
||||||
|
Ruft die Information über eine bestimmte Anwendung ab.
|
||||||
|
"""
|
||||||
|
url = f"{STEAM_API_URL}/ISteamApp/GetAppList/v0001/?key=80BED3ACB9E38E5A944F2BEB26FC9C3E&appids={app_id}"
|
||||||
|
response = requests.get(url)
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.text
|
||||||
|
return data
|
||||||
|
else:
|
||||||
|
print(f"Ein Fehler auftrat: {response.status_code}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def main():
|
||||||
|
user_info = get_user_info(USER_ID)
|
||||||
|
print("Benutzer-Informationen:")
|
||||||
|
for line in user_info.splitlines():
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
app_info = get_app_info(USER_ID) # oder USER_ID
|
||||||
|
print("\nAnwendung-Informationen:")
|
||||||
|
lines = app_info.splitlines()
|
||||||
|
while lines:
|
||||||
|
line = lines.pop(0)
|
||||||
|
if line.startswith("<"):
|
||||||
|
break
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
40
steam_api.py
Normal file
40
steam_api.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
# Steam-API-Einheitspunkt
|
||||||
|
STEAM_API_URL = "https://api.steampowered.com"
|
||||||
|
|
||||||
|
# Benutzer-ID oder Anwendung-ID
|
||||||
|
USER_ID = "76561197999844867" # ersetzen Sie mit der ID des Benutzers oder der Anwendung, für die Sie Informationen benötigen
|
||||||
|
|
||||||
|
def get_user_info(user_id):
|
||||||
|
"""
|
||||||
|
Ruft die Information über einen bestimmten Benutzer ab.
|
||||||
|
"""
|
||||||
|
url = f"{STEAM_API_URL}/ISteamUser/GetPlayerSummarInfo/v0001/?key=80BED3ACB9E38E5A944F2BEB26FC9C3E&steamids={user_id}"
|
||||||
|
response = requests.get(url)
|
||||||
|
data = json.loads(response.content)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_app_info(app_id):
|
||||||
|
"""
|
||||||
|
Ruft die Information über eine bestimmte Anwendung ab.
|
||||||
|
"""
|
||||||
|
url = f"{STEAM_API_URL}/ISteamApp/GetAppList/v0001/?key=80BED3ACB9E38E5A944F2BEB26FC9C3E&appids={app_id}"
|
||||||
|
response = requests.get(url)
|
||||||
|
data = json.loads(response.content)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def main():
|
||||||
|
user_info = get_user_info(USER_ID)
|
||||||
|
print("Benutzer-Informationen:")
|
||||||
|
for key, value in user_info["response"]["summarizeForPublic"]["player"].items():
|
||||||
|
print(f"{key}: {value}")
|
||||||
|
|
||||||
|
app_info = get_app_info(USER_ID) # oder USER_ID
|
||||||
|
print("\nAnwendung-Informationen:")
|
||||||
|
for item in app_info["app_list"]:
|
||||||
|
print(f"Name: {item['name']}, App ID: {item['appid']}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
28
test_skripte/check_port_is_open.py
Executable file
28
test_skripte/check_port_is_open.py
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
#! /usr/bin/env python3.12
|
||||||
|
import socket
|
||||||
|
import scapy.all as scapy
|
||||||
|
#result = sock.connect_ex(('ras-dan-01.local',22))
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||||
|
sock.settimeout(5)
|
||||||
|
result = sock.connect_ex(('192.168.50.217',22))
|
||||||
|
if result == 0:
|
||||||
|
print("Port is open")
|
||||||
|
else:
|
||||||
|
print("Port is not open")
|
||||||
|
|
||||||
|
#sock.close()
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
print(scan(ip='dan-jam-01'))
|
||||||
280
test_skripte/socket
Normal file
280
test_skripte/socket
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
%!PS-Adobe-3.0
|
||||||
|
%%Creator: (ImageMagick)
|
||||||
|
%%Title: (socket)
|
||||||
|
%%CreationDate: (2024-10-29T14:37:21+00:00)
|
||||||
|
%%BoundingBox: 3147 1726 3157 1727
|
||||||
|
%%HiResBoundingBox: 3147 1726 3157 1727
|
||||||
|
%%DocumentData: Clean7Bit
|
||||||
|
%%LanguageLevel: 1
|
||||||
|
%%Orientation: Portrait
|
||||||
|
%%PageOrder: Ascend
|
||||||
|
%%Pages: 1
|
||||||
|
%%EndComments
|
||||||
|
|
||||||
|
%%BeginDefaults
|
||||||
|
%%EndDefaults
|
||||||
|
|
||||||
|
%%BeginProlog
|
||||||
|
%
|
||||||
|
% Display a color image. The image is displayed in color on
|
||||||
|
% Postscript viewers or printers that support color, otherwise
|
||||||
|
% it is displayed as grayscale.
|
||||||
|
%
|
||||||
|
/DirectClassPacket
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% Get a DirectClass packet.
|
||||||
|
%
|
||||||
|
% Parameters:
|
||||||
|
% red.
|
||||||
|
% green.
|
||||||
|
% blue.
|
||||||
|
% length: number of pixels minus one of this color (optional).
|
||||||
|
%
|
||||||
|
currentfile color_packet readhexstring pop pop
|
||||||
|
compression 0 eq
|
||||||
|
{
|
||||||
|
/number_pixels 3 def
|
||||||
|
}
|
||||||
|
{
|
||||||
|
currentfile byte readhexstring pop 0 get
|
||||||
|
/number_pixels exch 1 add 3 mul def
|
||||||
|
} ifelse
|
||||||
|
0 3 number_pixels 1 sub
|
||||||
|
{
|
||||||
|
pixels exch color_packet putinterval
|
||||||
|
} for
|
||||||
|
pixels 0 number_pixels getinterval
|
||||||
|
} bind def
|
||||||
|
|
||||||
|
/DirectClassImage
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% Display a DirectClass image.
|
||||||
|
%
|
||||||
|
systemdict /colorimage known
|
||||||
|
{
|
||||||
|
columns rows 8
|
||||||
|
[
|
||||||
|
columns 0 0
|
||||||
|
rows neg 0 rows
|
||||||
|
]
|
||||||
|
{ DirectClassPacket } false 3 colorimage
|
||||||
|
}
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% No colorimage operator; convert to grayscale.
|
||||||
|
%
|
||||||
|
columns rows 8
|
||||||
|
[
|
||||||
|
columns 0 0
|
||||||
|
rows neg 0 rows
|
||||||
|
]
|
||||||
|
{ GrayDirectClassPacket } image
|
||||||
|
} ifelse
|
||||||
|
} bind def
|
||||||
|
|
||||||
|
/GrayDirectClassPacket
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% Get a DirectClass packet; convert to grayscale.
|
||||||
|
%
|
||||||
|
% Parameters:
|
||||||
|
% red
|
||||||
|
% green
|
||||||
|
% blue
|
||||||
|
% length: number of pixels minus one of this color (optional).
|
||||||
|
%
|
||||||
|
currentfile color_packet readhexstring pop pop
|
||||||
|
color_packet 0 get 0.299 mul
|
||||||
|
color_packet 1 get 0.587 mul add
|
||||||
|
color_packet 2 get 0.114 mul add
|
||||||
|
cvi
|
||||||
|
/gray_packet exch def
|
||||||
|
compression 0 eq
|
||||||
|
{
|
||||||
|
/number_pixels 1 def
|
||||||
|
}
|
||||||
|
{
|
||||||
|
currentfile byte readhexstring pop 0 get
|
||||||
|
/number_pixels exch 1 add def
|
||||||
|
} ifelse
|
||||||
|
0 1 number_pixels 1 sub
|
||||||
|
{
|
||||||
|
pixels exch gray_packet put
|
||||||
|
} for
|
||||||
|
pixels 0 number_pixels getinterval
|
||||||
|
} bind def
|
||||||
|
|
||||||
|
/GrayPseudoClassPacket
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% Get a PseudoClass packet; convert to grayscale.
|
||||||
|
%
|
||||||
|
% Parameters:
|
||||||
|
% index: index into the colormap.
|
||||||
|
% length: number of pixels minus one of this color (optional).
|
||||||
|
%
|
||||||
|
currentfile byte readhexstring pop 0 get
|
||||||
|
/offset exch 3 mul def
|
||||||
|
/color_packet colormap offset 3 getinterval def
|
||||||
|
color_packet 0 get 0.299 mul
|
||||||
|
color_packet 1 get 0.587 mul add
|
||||||
|
color_packet 2 get 0.114 mul add
|
||||||
|
cvi
|
||||||
|
/gray_packet exch def
|
||||||
|
compression 0 eq
|
||||||
|
{
|
||||||
|
/number_pixels 1 def
|
||||||
|
}
|
||||||
|
{
|
||||||
|
currentfile byte readhexstring pop 0 get
|
||||||
|
/number_pixels exch 1 add def
|
||||||
|
} ifelse
|
||||||
|
0 1 number_pixels 1 sub
|
||||||
|
{
|
||||||
|
pixels exch gray_packet put
|
||||||
|
} for
|
||||||
|
pixels 0 number_pixels getinterval
|
||||||
|
} bind def
|
||||||
|
|
||||||
|
/PseudoClassPacket
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% Get a PseudoClass packet.
|
||||||
|
%
|
||||||
|
% Parameters:
|
||||||
|
% index: index into the colormap.
|
||||||
|
% length: number of pixels minus one of this color (optional).
|
||||||
|
%
|
||||||
|
currentfile byte readhexstring pop 0 get
|
||||||
|
/offset exch 3 mul def
|
||||||
|
/color_packet colormap offset 3 getinterval def
|
||||||
|
compression 0 eq
|
||||||
|
{
|
||||||
|
/number_pixels 3 def
|
||||||
|
}
|
||||||
|
{
|
||||||
|
currentfile byte readhexstring pop 0 get
|
||||||
|
/number_pixels exch 1 add 3 mul def
|
||||||
|
} ifelse
|
||||||
|
0 3 number_pixels 1 sub
|
||||||
|
{
|
||||||
|
pixels exch color_packet putinterval
|
||||||
|
} for
|
||||||
|
pixels 0 number_pixels getinterval
|
||||||
|
} bind def
|
||||||
|
|
||||||
|
/PseudoClassImage
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% Display a PseudoClass image.
|
||||||
|
%
|
||||||
|
% Parameters:
|
||||||
|
% class: 0-PseudoClass or 1-Grayscale.
|
||||||
|
%
|
||||||
|
currentfile buffer readline pop
|
||||||
|
token pop /class exch def pop
|
||||||
|
class 0 gt
|
||||||
|
{
|
||||||
|
currentfile buffer readline pop
|
||||||
|
token pop /depth exch def pop
|
||||||
|
/grays columns 8 add depth sub depth mul 8 idiv string def
|
||||||
|
columns rows depth
|
||||||
|
[
|
||||||
|
columns 0 0
|
||||||
|
rows neg 0 rows
|
||||||
|
]
|
||||||
|
{ currentfile grays readhexstring pop } image
|
||||||
|
}
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% Parameters:
|
||||||
|
% colors: number of colors in the colormap.
|
||||||
|
% colormap: red, green, blue color packets.
|
||||||
|
%
|
||||||
|
currentfile buffer readline pop
|
||||||
|
token pop /colors exch def pop
|
||||||
|
/colors colors 3 mul def
|
||||||
|
/colormap colors string def
|
||||||
|
currentfile colormap readhexstring pop pop
|
||||||
|
systemdict /colorimage known
|
||||||
|
{
|
||||||
|
columns rows 8
|
||||||
|
[
|
||||||
|
columns 0 0
|
||||||
|
rows neg 0 rows
|
||||||
|
]
|
||||||
|
{ PseudoClassPacket } false 3 colorimage
|
||||||
|
}
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% No colorimage operator; convert to grayscale.
|
||||||
|
%
|
||||||
|
columns rows 8
|
||||||
|
[
|
||||||
|
columns 0 0
|
||||||
|
rows neg 0 rows
|
||||||
|
]
|
||||||
|
{ GrayPseudoClassPacket } image
|
||||||
|
} ifelse
|
||||||
|
} ifelse
|
||||||
|
} bind def
|
||||||
|
|
||||||
|
/DisplayImage
|
||||||
|
{
|
||||||
|
%
|
||||||
|
% Display a DirectClass or PseudoClass image.
|
||||||
|
%
|
||||||
|
% Parameters:
|
||||||
|
% x & y translation.
|
||||||
|
% x & y scale.
|
||||||
|
% label pointsize.
|
||||||
|
% image label.
|
||||||
|
% image columns & rows.
|
||||||
|
% class: 0-DirectClass or 1-PseudoClass.
|
||||||
|
% compression: 0-none or 1-RunlengthEncoded.
|
||||||
|
% hex color packets.
|
||||||
|
%
|
||||||
|
gsave
|
||||||
|
/buffer 512 string def
|
||||||
|
/byte 1 string def
|
||||||
|
/color_packet 3 string def
|
||||||
|
/pixels 768 string def
|
||||||
|
|
||||||
|
currentfile buffer readline pop
|
||||||
|
token pop /x exch def
|
||||||
|
token pop /y exch def pop
|
||||||
|
x y translate
|
||||||
|
currentfile buffer readline pop
|
||||||
|
token pop /x exch def
|
||||||
|
token pop /y exch def pop
|
||||||
|
currentfile buffer readline pop
|
||||||
|
token pop /pointsize exch def pop
|
||||||
|
x y scale
|
||||||
|
currentfile buffer readline pop
|
||||||
|
token pop /columns exch def
|
||||||
|
token pop /rows exch def pop
|
||||||
|
currentfile buffer readline pop
|
||||||
|
token pop /class exch def pop
|
||||||
|
currentfile buffer readline pop
|
||||||
|
token pop /compression exch def pop
|
||||||
|
class 0 gt { PseudoClassImage } { DirectClassImage } ifelse
|
||||||
|
grestore
|
||||||
|
showpage
|
||||||
|
} bind def
|
||||||
|
%%EndProlog
|
||||||
|
%%Page: 1 1
|
||||||
|
%%PageBoundingBox: 3147 1726 3157 1727
|
||||||
|
DisplayImage
|
||||||
|
3147 1726
|
||||||
|
10 1
|
||||||
|
12
|
||||||
|
10 1
|
||||||
|
0
|
||||||
|
0
|
||||||
|
1E22291E22291E22291E22291E22291E22291E22291E22291E22291E2229
|
||||||
|
|
||||||
|
%%PageTrailer
|
||||||
|
%%Trailer
|
||||||
|
%%EOF
|
||||||
Reference in New Issue
Block a user