-
Notifications
You must be signed in to change notification settings - Fork 0
/
Port_Scanner.py
53 lines (41 loc) · 1.26 KB
/
Port_Scanner.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
import socket
from IPy import IP
# 147.91.19.26
# 192.168.184.128
# Scan ports
def scan(target, portNumber):
converted_ip = check_ip(target)
print('\n' + '[-_0 Scanning Target] ' + str(target))
for port in range(1, portNumber):
scanPort(converted_ip, port)
# Convert domain name to ip address
def check_ip(ipaddress):
try:
IP(ipaddress)
return ipaddress
except:
return socket.gethostbyname(ipaddress)
# Grabbing service's details
def getBanner(sock):
return sock.recv(1024)
# this function will scan the port is open or not
def scanPort(ipaddress, port):
try:
sock = socket.socket()
sock.settimeout(0.5)
sock.connect((ipaddress, port))
try:
banner = getBanner(sock)
print("[+] Open Port " + str(port) + " : " + str(banner.decode().strip('\n')))
except:
print('[+] Open Port ' + str(port))
except:
pass
if __name__ == '__main__':
targets = input("[+] Enter Target/s To Scan:(split multiple targets by ,): ")
portNumber = input("[+] Enter Port Number To Scan: ")
if ',' in targets:
for ipAddress in targets.split(','):
scan(ipAddress.strip(' '), portNumber)
else:
scan(targets, portNumber)