worked on network.py

This commit is contained in:
EggMan 2024-04-24 10:28:56 -04:00
parent 8c71897bdf
commit 5842024abf

37
network.py Normal file
View File

@ -0,0 +1,37 @@
import socket
import time
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
print("Your IP address is: " + str(s.getsockname()[0]))
s.close()
import socket
openPorts = []
closedPorts = []
host = input("Please enter the IP address of the host you would like to scan: ")
start = input("Please enter the starting port you would like to scan: ")
end = input("Please enter the ending port you would like to scan: ")
timeout = input("Please enter the timeout in seconds you would like to set for each port scan: ")
for i in range(int(start), int(end)):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(float(timeout))
print("Scanning port " + str(i) + " on host " + host)
result = sock.connect_ex((host, i))
if result == 0:
openPorts.append(i)
else:
closedPorts.append(i)
# time.sleep(1)
sock.close()
for port in closedPorts:
print("Port " + str(port) + " is closed")
for port in openPorts:
print("Port " + str(port) + " is open")
print(str(len(closedPorts)) + " ports are closed; " + str(len(openPorts)) + " ports are open")