-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathportscan.py
More file actions
39 lines (34 loc) · 868 Bytes
/
portscan.py
File metadata and controls
39 lines (34 loc) · 868 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
import sys
import socket
def main():
args = sys.argv
if len(args) < 2:
print("[!]Falta argumentos para o programa! Saindo...")
sys.exit(1)
ip = args[1]
portas = args[2] if len(args) >= 3 else "1:65536"
portas = (x for x in range(int(portas.split(":")[0]), int(portas.split(":")[1])+1))
scan(ip, portas)
def banner(sckt, ip, porta):
try:
sckt.settimeout(1)
sckt.connect((ip, porta))
banner = sckt.recv(1024).decode().strip()
assert banner
return banner
except:
return "Unknown"
def child(ip, port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.settimeout(0.3)
if s.connect_ex((ip, port)) == 0:
print("{}/tcp open".format(port), end="|")
print(banner(s, ip, port))
except:
pass
def scan(ip, portas):
for c in portas:
child(ip, c)
if __name__ == '__main__':
main()