-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathportscannercaz.py
32 lines (28 loc) · 946 Bytes
/
portscannercaz.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
from socket import *
# Function to check if a port is open
def cScan(tgtHost, tgtPort):
try:
connskt = socket(AF_INET, SOCK_STREAM)
connskt.settimeout(1) # Set a timeout for the connection
connskt.connect((tgtHost, tgtPort))
print('[+] %d /tcp open' % tgtPort)
connskt.close()
except:
print('[-] %d /tcp closed' % tgtPort)
def portScan(tgtHost, tgtPorts):
try:
tgtIP = gethostbyname(tgtHost)
except:
print('[-] Unable to resolve %s' % tgtHost)
return
try:
tgtName = gethostbyaddr(tgtIP)
print('\n [+] Scan result for: %s ' % tgtName[0])
except:
print('\n [+] Scan result for: %s' % tgtIP)
setdefaulttimeout(1)
for tgtPort in tgtPorts:
print('Scanning Port: %d' % tgtPort)
cScan(tgtHost, int(tgtPort))
if __name__ == '__main__':
portScan('google.com', [80, 22])