-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPQuickLook.py
62 lines (45 loc) · 1.72 KB
/
IPQuickLook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import socket
import concurrent.futures
import os
ip = input("Enter the IP address you want to scan: ")
start_port = int(input("Enter the starting port for the scan(Example: 1): "))
end_port = int(input("Enter the ending port for the scan(Example: 1023): "))
def port_scan(ip, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(0.5)
try:
sock.connect((ip, port))
service = sock.recv(1024)
sock.close()
return (port, True, service.decode().strip())
except:
return (port, False, '')
def os_detection(ip):
response = os.popen(f"ping {ip} -n 1").read()
if "TTL=" in response:
return "Windows"
else:
response = os.popen(f"ping {ip} -c 1").read()
if "ttl=" in response:
return "Linux/Unix"
else:
return "Unknown"
print("(...", "Scanning IP address:", ip, "...)")
print(f"Testing target ports {start_port} to {end_port} to see if they are open...")
open_ports = []
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = []
for port in range(start_port, end_port + 1):
futures.append(executor.submit(port_scan, ip, port))
for future in concurrent.futures.as_completed(futures):
port, is_open, service = future.result()
if is_open:
print(" ", "- Port", port, "is open. Running:", service)
open_ports.append((port, service))
if len(open_ports) == 0:
print("No open ports found on IP address", ip)
os = os_detection(ip)
print(" ")
print("-> [", "The operating system of the target is:", os, "] <-")
print(" ")
print("---- SCAN FINISHED ----")