#! /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'))
