Skip to content

Commit 3a92750

Browse files
authored
Merge pull request #61 from jnzonzidi/patch-1
Update check-all-is-well.py
2 parents 7230987 + f123b3c commit 3a92750

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

check-all-is-well.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
11
import socket
22
import os
33
import requests
4-
import nmap3 # pip install python3-nmap
4+
import nmap3 # pip install python3-nmap
55

66
"""
7-
First Python Program
8-
Just to see if we can run python3 successfully
9-
and modules are installed or not ;)
7+
Python Script for Testing Environment
8+
Checks system information, IPs, and nmap functionality.
109
"""
1110

1211
name = "Sanjeev"
13-
print("Hello "+name+"\n")
14-
print("O.S. is: " + os.name)
15-
16-
hostname = socket.gethostname()
17-
local_ip = socket.gethostbyname(hostname)
18-
public_ip = requests.get('https://checkip.amazonaws.com').text.strip()
19-
print("Your Computer Name is:" + hostname)
20-
print("Your Computer Local IP Address is:" + local_ip)
21-
print("Your Computer Public IP Address is:" + public_ip)
12+
print(f"Hello {name}\n")
13+
print(f"O.S. is: {os.name}")
14+
15+
# Retrieve host information
16+
try:
17+
hostname = socket.gethostname()
18+
local_ip = socket.gethostbyname(hostname)
19+
print(f"Your Computer Name is: {hostname}")
20+
print(f"Your Computer Local IP Address is: {local_ip}")
21+
except Exception as e:
22+
print(f"Error retrieving local IP: {e}")
23+
24+
# Retrieve public IP
25+
try:
26+
public_ip = requests.get('https://checkip.amazonaws.com').text.strip()
27+
print(f"Your Computer Public IP Address is: {public_ip}")
28+
except Exception as e:
29+
print(f"Error retrieving public IP: {e}")
30+
2231
print("\nChecking if nmap works:\nStarting nmap scan now...\n")
2332

24-
# make nmap object
33+
# Initialize nmap object
2534
nmap = nmap3.Nmap()
2635

27-
#nmap version
28-
nmap_version = nmap.nmap_version()
29-
print (f"Nmap version: {nmap_version}")
36+
# Get nmap version
37+
try:
38+
nmap_version = nmap.nmap_version()
39+
print(f"Nmap version: {nmap_version}")
40+
except Exception as e:
41+
print(f"Error retrieving nmap version: {e}")
3042

31-
# scanning practical-devsecops.com
43+
# Perform a top ports scan
3244
url = 'aliencoders.org'
33-
""""
34-
print("Starting nmap scan for url: " + url)
35-
results = nmap.nmap_version_detection(url)
36-
print(f"Here is the result for {url}: {results}")
37-
"""
38-
top_ports = nmap.scan_top_ports(url, args="-sV")
39-
print(f"These are the top ports: {top_ports}")
45+
try:
46+
print(f"Starting nmap scan for URL: {url}")
47+
top_ports = nmap.scan_top_ports(url, args="-sV")
48+
print(f"Top ports for {url}: {top_ports}")
49+
except Exception as e:
50+
print(f"Error during nmap scan: {e}")

0 commit comments

Comments
 (0)