Use python-nmap, add requirements.txt, other improvments.

This commit is contained in:
Astatin3
2024-04-18 13:51:45 -06:00
parent 9f5bb236bd
commit 96285a4c58
12 changed files with 100 additions and 75 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
import libs.scanners.tcp80
import libs.scanners.tcp80 as tcp80
def scan(host:str, port:int):
return tcp80.scan(host, port)
+9 -8
View File
@@ -88,6 +88,7 @@ def scan(address:str, port:str):
ssl_sock = context.wrap_socket(sock, server_hostname=address)
returnVal = ""
error = False
try:
# Connect to the server
@@ -96,24 +97,24 @@ def scan(address:str, port:str):
ssl_sock.sendall(generate_headers().encode())
cert = ssl_sock.getpeercert(binary_form=True)
# Receive the response
response = b""
# Receive the response
while True:
chunk = ssl_sock.recv(64)
if not chunk: break
response += chunk
returnVal = f"Response {response.decode()}" + "\n"
returnVal += chunk.decode()
returnVal += "\n"
returnVal += "SSL Certificate Information:\n"
returnVal += get_ssl_cert_info(cert) + "\n"
returnVal += "######### \n"
except socket.error as e:
returnVal = f"<Error> (possible connection reset) {e}"
except Exception as e:
returnVal += f"<error {e}>"
error = True
finally:
if ssl_sock:
ssl_sock.close()
return returnVal
return returnVal, error
+1 -1
View File
@@ -1,4 +1,4 @@
import libs.scanners.tcp80
import libs.scanners.tcp80 as tcp80
def scan(host:str, port:int):
return tcp80.scan(host, port)
+6 -8
View File
@@ -17,6 +17,7 @@ def generate_headers():
def scan(host:str, port:int):
returnVal = ""
error = False
try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((host, port))
@@ -28,21 +29,18 @@ def scan(host:str, port:int):
client_socket.send(request.encode())
response = b""
while True:
chunk = client_socket.recv(64)
if not chunk: break
response += chunk
returnVal += chunk.decode()
returnVal = "Response: " + response.decode()
except:
returnVal = "<Error> (possible connection reset)"
except Exception as e:
returnVal += f"<error {e}>"
error = True
finally:
if client_socket:
client_socket.close()
return returnVal
return returnVal, error
+1 -1
View File
@@ -1,4 +1,4 @@
import libs.scanners.tcp80
import libs.scanners.tcp80 as tcp80
def scan(host:str, port:int):
return tcp80.scan(host, port)
+1 -1
View File
@@ -1,4 +1,4 @@
import libs.scanners.tcp80
import libs.scanners.tcp80 as tcp80
def scan(host:str, port:int):
return tcp80.scan(host, port)
+1 -1
View File
@@ -1,4 +1,4 @@
import libs.scanners.tcp80
import libs.scanners.tcp80 as tcp80
def scan(host:str, port:int):
return tcp80.scan(host, port)
+6 -8
View File
@@ -3,6 +3,7 @@ import time
def scan(address:str, port:int, timeout:int=5):
returnVal = ""
error = False
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -11,24 +12,21 @@ def scan(address:str, port:int, timeout:int=5):
client_socket.settimeout(timeout)
start_time = time.time()
outBytes = b''
while time.time() - start_time < timeout:
try:
data = client_socket.recv(64)
if not data: break
outBytes += data
returnVal += data.decode()
except socket.timeout:
break
returnVal = f'({address}:{port}) Recieved: {outBytes.decode()}'
except socket.error as e:
print(f"Error: {e}")
returnVal = f'({address}:{port}) Recieved: <error>'
except Exception as e:
returnVal += f'<error {e}>'
error = True
finally:
client_socket.close()
return returnVal
return returnVal, error
+1 -1
View File
@@ -1,2 +1,2 @@
def scan(address:str, port:int):
return f'<{address}:{port}>'
return f'<{address}:{port}>', False