forked from The-Art-of-Hacking/h4cker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quick_scanner.py
62 lines (49 loc) · 1.6 KB
/
quick_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
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# Author: Omar Santos @santosomar
# version 1.0
# This is a quick demonstration on how to create a
# basic TCP port scanner using python.
#####################################################################
from __future__ import print_function
import socket, subprocess, sys
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
subprocess.call('clear', shell=True)
print('''\t
___ __ __ _ ___ _ ___
/ _ \| \/ | /_\ | _ ( ) __|
| (_) | |\/| |/ _ \| //\__ \
\___/|_| _|_/_/_\_\_|_\ |___/
| | |_ _|_ _|_ _| | | __|
| |__ | | | | | | | |__| _|
|____|___| |_| _|_| |____|___|__
/ __|/ __| /_\ | \| | \| | __| _ \\
\__ \ (__ / _ \| .` | .` | _|| /
|___/\___/_/ \_\_|\_|_|\_|___|_|_\\
''')
target_ip = raw_input("\t Please enter the IP address of the target host:").strip()
port_1 = int(raw_input("\t Enter the first port to scan:\t").strip())
port_2 = int(raw_input("\t Enter the last port to scan:\t").strip())
print("~"*50)
print("\n ...scanning target now. ", target_ip)
print("~"*50)
try:
for port in range(port_1, port_2):
sock= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
result = sock.connect_ex((target_ip, port))
if result==0:
print("Found open port:\t", port)
sock.close()
except KeyboardInterrupt:
print("[!] Scan stopped by user... ")
sys.exit()
except socket.gaierror:
print("[!] The target's hostname could not be resolved...")
sys.exit()
except socket.error:
print("[!] Target is unreachable...")
sys.exit()
print("The scan is complete. Happy hacking!")