35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
from scapy.all import IP, ICMP, sr1, conf, TCP, ARP, Ether, srp, UDP, DNS, DNSQR, Packet
|
|
|
|
conf.sniff_promisc = False
|
|
|
|
cible = "79.137.78.240" # datafrance.fr, le site de Rachid
|
|
ports = [22, 80, 443, 8080, 3306]
|
|
|
|
# __truediv__
|
|
for port in ports:
|
|
paquet = IP(dst= cible) / TCP(dport= port, flags= 'S')
|
|
reponse = sr1(paquet, timeout= 1, verbose= 0)
|
|
|
|
if reponse and reponse[TCP].flags == 'SA': # SYN-ACK, le serveur répond "oui" aux connexions
|
|
print(f"Port {port}: ouvert")
|
|
else:
|
|
print(f"Port {port}: fermé ou filtré")
|
|
|
|
|
|
paquet = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst="192.168.1.0/24") # Ether : adresse Broadcast (tous les appareils) / ARP : "qui a cette adresse ?"
|
|
reponses, _ = srp(paquet, timeout= 2, verbose= 0)
|
|
print(f"{len(reponses)} hôtes détectés: ")
|
|
|
|
for envoi, reception in reponses:
|
|
print(f"{reception.psrc} -> {reception.hwsrc}")
|
|
|
|
|
|
requete = IP(dst= '1.1.1.1') / UDP(dport= 53) / DNS(
|
|
rd= 1, # Recursive Desired (demande une réponse)
|
|
qd= DNSQR(qname= "datafrance.fr") # Résolution de datafrance.fr
|
|
)
|
|
|
|
reponse = sr1(requete, timeout= 2, verbose= 0)
|
|
if reponse and reponse.haslayer(DNS):
|
|
for i in range(reponse[DNS].ancount):
|
|
print(reponse[DNS].an[i].rdata) # rdata : Response Data |