Simple Port Scanner in Python using SOCKET Library -Getting started with Python for Network Security
Code is available at:
https://github.com/cloudsecuritylabs/...
import socket
A class to scan ports using simple Python
class PortScanner:
def __init__(self, ip):
self.ip = ip
self.open_ports = []
Scan a range of ports
def scan_ips(self, starting_ip, ending_ip):
for port in range(starting_ip, ending_ip + 1):
print(f'scanning {port} ....')
if port is open update the list
if self.is_open(port):
self.open_ports.append(port)
this function checks for open port using socket library
def is_open(self, port):
s = socket.socket()
exit_code = s.connect_ex((self.ip, port))
s.close()
if exit_code == 0:
return True
else:
return False
write open ports to a file of your choosing
def write_to_file(self, path_to_file):
with open(path_to_file, "a") as f:
for port in self.open_ports:
print(port)
f.write(str(port) + "\n")
def main():
ip = input("Enter the IP to scan: ")
starting_port = int(input("Enter the lower end of port to scan: "))
ending_port = int(input("Enter the upper end of port to scan: "))
scanner = PortScanner(ip)
scanner.scan_ips(starting_port, ending_port)
print(scanner.open_ports)
scanner.write_to_file("open_ports.txt")
if _name_ == '__main__':
main()
Nesta página do site você pode assistir ao vídeo on-line Simple Port Scanner in Python using SOCKET Library -Getting started with Python for Network Security duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Cloud Security Training & Consulting 24 Abril 2022, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 589 vezes e gostou 1 espectadores. Boa visualização!