-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathportscanner.py
40 lines (34 loc) · 1000 Bytes
/
portscanner.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
import socket
from IPy import IP
def scan(target):
converted_ip = check_ip(target)
print('\n' + '[-_0 Scanning Target] ' + str(target))
for port in range(1,500):
scan_port(converted_ip, port)
def check_ip(ip):
try:
IP(ip)
return(ip)
except ValueError:
return socket.gethostbyname(ip)
def get_banner(s):
return s.recv(1024)
def scan_port(ipaddress, port):
try:
sock = socket.socket()
sock.settimeout(0.5)
sock.connect((ipaddress, port))
try:
banner = get_banner(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 with ,): ')
if ',' in targets:
for ip_add in targets.split(','):
scan(ip_add.strip(' '))
else:
scan(targets)