-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·187 lines (175 loc) · 5.61 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/python3
import socket
import argparse
import time
import sys
import os
from threading import Thread
HOST = None
PORT = None
flag1= False
flag2= False
def usend():
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.bind((HOST, PORT))
except OSError as e:
print(e)
exit()
except Exception:
print("Sorry Something Went Wrong!!")
exit()
s.listen(4)
conn, addr = s.accept()
with conn:
#print('Connected to', addr)
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)
def ureceive():
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.connect((HOST, PORT))
s.settimeout(5)
try:
s.sendall(b'T3cH_W1z4rD')
data = s.recv(1024)
except socket.timeout:
exit()
#print('Received', repr(data))
if len(repr(data))>0:
flag1=True
def tsend():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.bind((HOST, PORT))
except OSError as e:
print(e)
exit()
except Exception:
print("Sorry Something Went Wrong!!")
exit()
s.listen(4)
conn, addr = s.accept()
with conn:
#print('Connected to', addr)
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)
def treceive():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.settimeout(5)
try:
s.sendall(b'T3cH_W1z4rD')
data = s.recv(1024)
except socket.timeout:
exit()
#print('Received', repr(data))
if len(repr(data))>0:
flag1=True
def banner():
print("\033[96m")
print(r''' ::::::::: :::::::: ::::::::: ::::::::::: ::::::::: ::::::::: :::::::: ::::::::: :::::::::: :::::::::
:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
+#++:++#+ +#+ +:+ +#++:++#: +#+ +#++:++#+ +#++:++#: +#+ +:+ +#++:++#+ +#++:++# +#++:++#:
+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+#
### ######## ### ### ### ### ### ### ######## ######### ########## ### ### ''')
print("\n\033[00m")
def scanner():
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
print("")
try:
if args.host:
ip=socket.gethostbyname_ex(args.host)[2][0]
else:
ip=args.ip
if args.PORT:
print("Scanning {} on {}".format(ip,args.PORT))
for port in args.PORT.split():
if s.connect_ex((ip,int(port)))==0:
print("Port {} is OPEN".format(port))
else:
if args.a==True:
print("Port {} is CLOSED".format(port))
pass
s.close()
else:
portrange=args.port
print("Scanning {} for range {}".format(ip,portrange))
for port in range(1,portrange):
code=s.connect_ex((ip,port))
if code==0:
print("Port {} is OPEN".format(port))
elif args.a==True:
if code==11:
print("Port {} is Filtered".format(port))
else:
print("Port {} is CLOSED".format(port))
except socket.gaierror:
print("Unknown Host: ",ip)
except KeyboardInterrupt:
print("\nExiting...")
finally:
print("\nThank You")
if __name__=='__main__':
banner()
parser=argparse.ArgumentParser(description="Port Prober \n\nexample: python3 main.py -i 172.217.31.196 -p 1000\n python3 main.py -H www.google.com -P \"21 22 53 80 443 445\" ",formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-i',"--ip",default="127.0.0.1",help='IP Address of Host (default: 127.0.0.1) ')
parser.add_argument('-H',"--host",default="localhost",type=str,help='Host Name (default: secarmy.org) ')
parser.add_argument('-p',"--port",type=int,default=1000,help='Range of Port')
parser.add_argument('-a',action="store_true",help='Aggressive Scanning')
parser.add_argument('-P',"--PORT",type=str,help='List of Particular Ports (Example: --PORT "21 22 80 443")')
parser.add_argument("-v", "--version", help="Prints Version", action="store_true")
parser.add_argument("-f", "--port-forwardable", dest='pf',type=int,help="To Check whether Open Port is Forwardable or not")
args = parser.parse_args()
count=4
while count!=0:
sys.stdout.write('\rStarting the Scanner |')
time.sleep(0.1)
sys.stdout.write('\rStarting the Scanner /')
time.sleep(0.1)
sys.stdout.write('\rStarting the Scanner -')
time.sleep(0.1)
sys.stdout.write('\rStarting the Scanner \\')
time.sleep(0.1)
count-=1
sys.stdout.write('\rDone! ')
print()
if args.version==True:
print("Version: 1.0.0")
exit()
elif args.pf:
if args.host:
ip=socket.gethostbyname_ex(args.host)[2][0]
else:
ip=args.ip
HOST = ip
PORT=args.pf
print("Checking for Forwarding")
t1=Thread(target = tsend)
t2=Thread(target = treceive)
t1.start()
t2.start()
t1.join()
t2.join()
#t1=Thread(target = usend)
#t2=Thread(target = ureceive)
#t1.start()
#t2.start()
t1.join()
t2.join()
if flag1==True and flag2==True:
print("Port {} is Forwardable".format(PORT))
else:
print("Port {} is Not Forwardable".format(PORT))
else:
scanner()