Skip to content

Commit eee6fb1

Browse files
authored
Add files via upload
1 parent 08b7bdd commit eee6fb1

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

port scanner/ReadMe.txt.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Description: This Python script is a simple port scanner that allows you to scan a target IP address for open ports within a specific range (from port 1 to port 99).This script serves as a basic port scanner that helps identify open ports on a target system and can be useful for network diagnostics and security assessments. However, it is essential to note that some systems might block port scanning activities, and performing scanning without proper authorization is unethical and potentially illegal. Always ensure you have proper permission before scanning any network or system.
2+
3+
Steps:
4+
5+
1.cd port scanner
6+
2.python port_scanner.py 192.168.0.1
7+
[Sample IP Address, Use your own IP address]

port scanner/port_scanner.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import sys
2+
import socket
3+
import argparse
4+
from datetime import datetime
5+
6+
def scan_ports(target, ports):
7+
open_ports = []
8+
for port in ports:
9+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10+
socket.setdefaulttimeout(1)
11+
result = s.connect_ex((target, port))
12+
if result == 0:
13+
open_ports.append(port)
14+
s.close()
15+
return open_ports
16+
17+
18+
19+
def main():
20+
parser = argparse.ArgumentParser(description="Simple port scanner.")
21+
parser.add_argument("target", help="Target IP address to scan.")
22+
parser.add_argument("-p", "--ports", type=str, default="1-100", help="Port range to scan (e.g., '1-100').")
23+
args = parser.parse_args()
24+
25+
target = socket.gethostbyname(args.target)
26+
port_range = args.ports.split("-")
27+
start_port = int(port_range[0])
28+
end_port = int(port_range[1])
29+
30+
print(f"Scanning Target: {target}")
31+
print(f"Scanning started at: {datetime.now()}")
32+
print("-" * 50)
33+
34+
try:
35+
open_ports = scan_ports(target, range(start_port, end_port + 1))
36+
if open_ports:
37+
print("Open Ports:")
38+
for port in open_ports:
39+
print(f"Port {port} is open")
40+
else:
41+
print("No open ports found in the specified range.")
42+
except KeyboardInterrupt:
43+
print("\nExiting Program!")
44+
sys.exit()
45+
except socket.gaierror:
46+
print("Hostname Could Not Be Resolved!")
47+
sys.exit()
48+
except socket.error:
49+
print("Server not responding!")
50+
sys.exit()
51+
52+
if __name__ == "__main__":
53+
main()

0 commit comments

Comments
 (0)