-
Notifications
You must be signed in to change notification settings - Fork 2
/
testpy.py
executable file
·178 lines (134 loc) · 3.87 KB
/
testpy.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
import socket, nmap, os
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
# This script will test our network
# Global_Constants
ipclass = ip[0:2]
def main():
if ipclass == '10':
menu_inside()
elif ipclass == '19':
menu_outside()
else:
print('You are not connected correctly')
exit()
def print_menu():
print('-' * 25)
print('1. Test FW')
print('2. Test Webserver')
print('3. Test Work Station')
print('4. To exit program')
print('-' * 25)
return
def menu_inside():
#clearing screen when reloading menu
print('Inside Menu')
os.system("clear")
#calling function that prints the menu
print_menu()
#asking for user input menu option
user_inside = str(input('Enter your choice:'))
if user_inside == '1':
testfw_in()
elif user_inside == '2':
testweb_in()
elif user_inside == '3':
testws_in()
elif user_inside == '4':
exit()
else:
print('kys')
menu_inside()
def menu_outside():
#clearing screen when reloading menu
os.system("clear")
#printing the menu options
print('Outside Menu')
print_menu()
#asking for user input menu option
user_inside = str(input('Enter your choice:'))
if user_inside == '1':
testfw_out()
elif user_inside == '2':
testweb_out()
elif user_inside == '3':
testws_out()
elif user_inside == '4':
exit()
else:
print('kys')
menu_outside()
def testfw_in():
devicename = str(input('Enter IP of Firewall:'))
nm = nmap.PortScanner()
nm.scan(devicename, '1-123')
print(nm.all_hosts())
for host in nm.all_hosts():
print('-' * 25)
print('Host : %s (%s)' % (host, nm[host].hostname()))
print('State : %s' % nm[host].state())
for proto in nm[host].all_protocols():
print('-' * 10)
print('Protocol : %s' % proto)
lport = nm[host][proto].keys()
for port in lport:
print('port : %s\tstate : %s' % (port, nm[host][proto][port]['state']))
if ping_check(devicename):
print(devicename, 'Is up')
else:
print(devicename, 'Is down')
input()
def testweb_in():
hostname = str(input('Enter IP of Webserver:'))
if ping_check(hostname):
print(hostname, 'Is up')
else:
print(hostname, 'Is down')
input()
def testws_in():
hostname = str(input('Enter IP of Webserver:'))
if ping_check(hostname):
print(hostname, 'Is up')
else:
print(hostname, 'Is down')
input()
def testfw_out():
devicename = str(input('Enter IP of Firewall:'))
nm = nmap.PortScanner()
nm.scan(devicename, '1-512')
print(nm.all_hosts())
for host in nm.all_hosts():
print('-' * 25)
print('Host : %s (%s)' % (host, nm[host].hostname()))
print('State : %s' % nm[host].state())
for proto in nm[host].all_protocols():
print('-' * 10)
print('Protocol : %s' % proto)
lport = nm[host][proto].keys()
for port in lport:
print('port : %s\tstate : %s' % (port, nm[host][proto][port]['state']))
if ping_check(devicename):
print(devicename, 'Is up')
else:
print(devicename, 'Is down')
input()
def ping_check(host_or_ip):
response = os.system("ping " + host_or_ip + " -c 1 > /dev/null 2>&1")
return response == 0
def testweb_out():
hostname = str(input('Enter IP of Webserver:'))
if ping_check(hostname):
print(hostname, 'Is up')
else:
print(hostname, 'Is down')
input()
def testws_out():
hostname = str(input('Enter IP of Webserver:'))
if ping_check(hostname):
print(hostname, 'Is up')
else:
print(hostname, 'Is down')
input()
main()