v_space_check/v9serv_check.py

39 lines
1.4 KiB
Python

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
import concurrent.futures
services = [
'https://g6.network/',
'https://cryptoctf.org/',
]
ip_address = "209.250.246.26"
ports = [80, 443]
def check_service(srv):
try:
r = requests.get(srv, timeout=4) # Added timeout for better control
if r.status_code != 200:
print(f"{srv}\n{r.status_code}")
except Exception as e: # It's better to catch a specific exception, but for demonstration, we use a general one.
print(f"Problem with {srv}: {e}")
def check_ports(port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(4)
result = sock.connect_ex((ip_address, port))
if result == 0:
print(f"{ip_address} on port {port}: OPEN")
else:
print(f"{ip_address} on port {port}: CLOSED or FILTERED")
# Use ThreadPoolExecutor to manage a pool of threads
# Adjust the max_workers based on your requirements or leave it as default to let Python decide
with concurrent.futures.ThreadPoolExecutor(max_workers=120) as executor:
# Map the function and its arguments to the executor
# The map function returns results in the order that the calls were started
executor.map(check_service, services)
with concurrent.futures.ThreadPoolExecutor(max_workers=120) as executor:
executor.map(check_ports, ports)