Setting up Hackers Used # Port Scanner
As simply Port scanning is like knocking on doors in a neighborhood to see who's home.
In the world of network security, it's a crucial step to identify open ports and potential vulnerabilities in your network.
Port scanning is a useful technique for exploring network systems and gathering information about their services.
Used Parties
Security professionals and system administrators use port scanning to diagnose network problems, audit network security, or discover vulnerabilities.
Why Port Scanning
It's kind of a enumeration process that defines the ports on a network or targeted machines which open and receive or send. It's sending the crafted packet to analyse the response and determine software and associated vulnerabilities on each port.
Socket Programming
A socket is an endpoint of a two-way communication server with a socket and is bounded by a specific port number as an 80 network. These are bounded with specific port numbers and use backend software to receive and process data before sending it back, generally
Basic Concept
The basic concept of a port scanner is to attempt a connection to a specific port at an IP address. If the connection is successful, we know there’s a service listening on that port. If not, then the port is closed.
Simple coding on Python
Import socket
import concurrent.futures
def scan_port(ip, port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(1)
try:
s.connect((ip, port))
return True
except:
return False
def port_scanner(ip, start_port, end_port):
ports = []
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
future_to_port = {executor.submit(scan_port, ip, port): port for port in range(start_port, end_port+1)}
for future in concurrent.futures.as_completed(future_to_port):
port = future_to_port[future]
if future.result():
print(f'Port {port} is open!')
ports.append(port)
return ports
# Test
open_ports = port_scanner('localhost', 1, 100)
print("Open ports:", open_ports)
Comments
Post a Comment