-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPort_Scanner.py
More file actions
39 lines (32 loc) · 985 Bytes
/
Port_Scanner.py
File metadata and controls
39 lines (32 loc) · 985 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
39
#!/bin/python
import sys
import socket
from datetime import datetime
#Define our target
if len(sys.argv) == 2:
target = socket.gethostbyname(sys.argv[1]) #translate hostname to IPV4
else:
print("Invalid anmount of arguments")
print("Syntax: Python3 Scanner.py <ip>")
#Add a banner
print("-" * 50)
print("Scanner target "+target)
print("Time started "+str(datetime.now()))
print("-" * 50)
try:
for port in range(1,10000):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
result = s.connect_ex((target,port)) #returns an error indicator
if result == 0:
print("Port {} is open".format(port))
s.close()
except KeyboardInterrupt:
print("\nExiting program. ")
sys.exit()
except socket.gaierror:
print("Hostname could not be resolved.")
sys.exit()
except socket.error:
print("Couldn't connect to server.")
sys.exit()