Skip to content

Commit 4d2793d

Browse files
authored
Add files via upload
1 parent e5773f6 commit 4d2793d

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

linux/python_nmap/Readme.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Requirements:
2+
Install the required library:
3+
4+
bash
5+
Copy
6+
pip install python-nmap
7+
Nmap must be installed on your system:
8+
9+
Linux: sudo apt-get install nmap
10+
11+
macOS: brew install nmap
12+
13+
Windows: Download from nmap.org
14+
15+
Usage:
16+
bash
17+
Copy
18+
python nmap_scanner.py <target> [-p <port-range>]
19+
Examples:
20+
Scan default ports (1-1000):
21+
22+
bash
23+
Copy
24+
python nmap_scanner.py 192.168.1.1
25+
Scan specific ports:
26+
27+
bash
28+
Copy
29+
python nmap_scanner.py example.com -p 20-80
30+
Scan single port:
31+
32+
bash
33+
Copy
34+
python nmap_scanner.py 10.0.0.1 -p 443
35+
Notes:
36+
The script shows port numbers, states (open/filtered/closed), and service names
37+
38+
You might need root/sudo privileges to scan certain ports
39+
40+
The scan might take some time depending on the target and port range
41+
42+
Always ensure you have proper authorization before scanning any network
43+
44+
This script provides more detailed output than a simple port scanner, including:
45+
46+
Host status (up/down)
47+
48+
Protocol type (TCP/UDP)
49+
50+
Port state (open/closed/filtered)
51+
52+
Service detection
53+
54+
Remember to use this tool responsibly and only on networks where you have explicit permission to perform scanning.

linux/python_nmap/python-nmap.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import nmap
2+
import argparse
3+
4+
def main(target, ports):
5+
# Initialize the PortScanner
6+
nm = nmap.PortScanner()
7+
8+
# Perform the scan
9+
print(f"Scanning {target} on ports {ports}...")
10+
nm.scan(target, ports)
11+
12+
# Check if the scan was successful
13+
if not nm.all_hosts():
14+
print("No hosts found or target is unreachable.")
15+
return
16+
17+
# Iterate through scan results
18+
for host in nm.all_hosts():
19+
print(f"\nHost: {host} ({nm[host].hostname()})")
20+
print(f"State: {nm[host].state()}")
21+
22+
# Iterate through all protocols (tcp, udp, etc.)
23+
for proto in nm[host].all_protocols():
24+
print(f"\nProtocol: {proto}")
25+
26+
# Get list of ports
27+
list_ports = nm[host][proto].keys()
28+
29+
# Print header
30+
print(f"PORT\tSTATE\tSERVICE")
31+
32+
# Iterate through each port
33+
for port in list_ports:
34+
state = nm[host][proto][port]['state']
35+
service = nm[host][proto][port]['name']
36+
print(f"{port}/{proto}\t{state}\t{service}")
37+
38+
if __name__ == "__main__":
39+
# Set up command-line arguments
40+
parser = argparse.ArgumentParser(description='Simple Nmap Scanner')
41+
parser.add_argument('target', help='Target IP address or hostname')
42+
parser.add_argument('-p', '--ports',
43+
help='Port range to scan (default: 1-1000)',
44+
default='1-1000')
45+
args = parser.parse_args()
46+
47+
main(args.target, args.ports)

0 commit comments

Comments
 (0)