-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.py
More file actions
38 lines (32 loc) · 893 Bytes
/
scanner.py
File metadata and controls
38 lines (32 loc) · 893 Bytes
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
#!/bin/python3
import socket
import sys
from datetime import datetime
#DEFINE OUR TARGET
if len(sys.argv) == 2:
target=socket.gethostbyname(sys.argv[1]) #translating hostname to IPv4
else:
print("Invalid amount of arguments.")
print("Syntax python3 scanner.py <ip>")
print("-"*50)
print("SCANNING TARGET "+target)
print("TIME STARTED " +str(datetime.now()))
print("-"*50)
try:
for port in range(1, 65535):
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
result=s.connect_ex((target,port)) #returns an error indicator
#print("Checking port {}".format(port))
if result==0:
print("Port {} is open".format(port))
s.close()
except KeyboardInterrupt:
print("\nExiting Program")
sys.exit()
except socket.gaierror:
print("Hostaname could not be resolved.")
sys.exit()
except socket.error:
print("Couldn't connect to server.")
sys.exit()