-
Notifications
You must be signed in to change notification settings - Fork 0
/
Second_Mind.py
138 lines (130 loc) · 7.67 KB
/
Second_Mind.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
import SSH
import os
import time
def Run_App():
os.system("cls")
print("SSH Connection\n"
"--------------------")
hostname = input('please enter IP or Host name: ') # Hostname or ip address.
port = int(input('please enter port: ')) # Port Number for ssh connection.
username = input('please enter username: ') # Username for authentication.
password = input('please enter password: ') # Password for password-based authentication (optional).
connection = SSH.SSH_Connection(hostname=hostname, port=port, username=username, password=password)
time.sleep(3)
if not connection: # connection is not valid
response = input("Do you want to Try again?\n"
" (y or n) :")
if response == "y" or response == "Y" or response == "yes": # Try again
Run_App()
else:
SSH.Close_SSH_Connection()
elif connection: # Run Command function to start configuring
Run_Command()
def Run_Command():
key = 1 # if key is 1 the app will be in a loop anf if key is 0 the app will be closed
os.system("cls")
SSH.Command("interface/print") # print all interfaces
input('Press Enter to continue...')
while key == 1:
time.sleep(1)
os.system("cls")
print("0| Close the Connection\n"
"1| Command Line\n"
"2| Reset the default configuration\n"
"3| Change system identity\n"
"4| Set Static IP\n"
"5| Configure DHCP\n"
"6| Configure NAT\n"
"7| Configure DNS-Server\n"
"8| Setup HomeCPE")
command = int(input("Choose an option :"))
if command == 0: # If user selects 0, the connection will be closed
SSH.Close_SSH_Connection() # close the ssh connection
time.sleep(2)
elif command == 1: # If user selects 1, free command line will be opened
os.system("cls")
print("COMMAND LINE\n"
"Enter 0 to exit"
"--------------------")
os.system("cls")
print("COMMAND LINE\n"
"------------")
while True:
command = input('>>>') # input command
SSH.Command(command)
if command == '0': # if the user enter 0, the command line will be closed
Run_Command()
break
elif command == 2: # If user selects 2,the default config will be reset
os.system("cls")
print('RESETTING SYSTEM CONFIGURATION\n'
'--------------------')
SSH.Command("system/reset-configuration no-defaults=yes") # reset the default config
SSH.Command("y")
print("wait few seconds")
time.sleep(7)
Run_App()
elif command == 3: # If user selects 3,system identity will be changed
os.system("cls")
print('CHANGE SYSTEM IDENTITY\n'
'--------------------')
name = input("Name :") # new identity name
SSH.Command(f'system/identity/set name={name}') # set the new name
elif command == 4: # If user selects 4,a static ip will be set to an interface
ip = input("Choose the IP(with subnet mask) :") # ip address
interface = input("Choose the Interface(Only The Number) :") # interface
SSH.Command(f'ip/address/add address={ip} interface=ether{interface}') # the command to set the static ip
elif command == 5: # If user selects 5,dhcp configuration will be started
os.system("cls")
print('CONFIGURING DHCP\n'
'------------')
print("1| DHCP-Client\n"
"2| DHCP-Server")
dhcp = int(input()) # choose between dhcp server and client
if dhcp == 1: # if the user selects 1, the dhcp client will be set
interface = input("Choose the Interface(Only The Number) :") # the interface to set dhcp client on it
SSH.Command(f'ip/dhcp-client/add interface=ether{interface} disabled=no') # set the dhcp client
elif dhcp == 2: # if the user selects 2, the dhcp server will be set
print('Enter the questions empty for default configuration')
interface = input("Choose the Interface(Only The Number) :") # interface
if not interface.strip(): # check if interface is empty or not
SSH.Command('interface/bridge/add name=Default-DHCP')
SSH.Command('interface/bridge/port/add bridge=Default-DHCP interface=ether2')
SSH.Command('interface/bridge/port/add bridge=Default-DHCP interface=ether3')
SSH.Command('interface/bridge/port/add bridge=Default-DHCP interface=ether4')
SSH.Command('interface/bridge/port/add bridge=Default-DHCP interface=ether5')
SSH.Command('interface/bridge/port/add bridge=Default-DHCP interface=wlan1')
SSH.Command('interface/bridge/port/add bridge=Default-DHCP interface=wlan2')
ip_ranges = input("Choose the IP(with subnet mask) :") # ip address
if not ip_ranges.strip(): # check ip ranges is empty or not
SSH.Command('ip/pool/add name=Default-DHCP ranges=192.168.150.2-192.168.150.254')
SSH.Command('ip/address/add address=192.168.150.1 interface=Default-DHCP')
SSH.Command('ip/dhcp-server/add address-pool=Default-DHCP interface=Default-DHCP disabled=no')
else: # both is empty
pool_name = input("Choose a name for your IP-pool :")
SSH.Command(f'ip/pool/add name={pool_name} ranges={ip_ranges}')
SSH.Command(f'ip/dhcp-server/add address-pool={pool_name} interface=ether{interface} disabled=no')
elif command == 6: # If user selects 6,the nat configuration will be started
os.system("cls")
interface = input("Choose the Interface(Only The Number) :")
SSH.Command(f'/ip/firewall/nat/ add chain=srcnat out-interface=ether{interface} action=masquerade')
elif command == 7: # If user selects 7,dns configuration will be started
os.system("cls")
print('CONFIGURING DNS\n'
'------------')
dns = input("DNS server :") # dns server
SSH.Command(f'ip/dns/set servers={dns}') # set the dns server
elif command == 8: # If user selects 8,HomeCPE configuration will be started
SSH.Command('ip/dhcp-client/add interface=ether1 disabled=no')
SSH.Command('interface/bridge/add name=HomeCPE-Bridge')
SSH.Command('interface/bridge/port/add bridge=HomeCPE-Bridge interface=ether2')
SSH.Command('interface/bridge/port/add bridge=HomeCPE-Bridge interface=ether3')
SSH.Command('interface/bridge/port/add bridge=HomeCPE-Bridge interface=ether4')
SSH.Command('interface/bridge/port/add bridge=HomeCPE-Bridge interface=ether5')
SSH.Command('interface/bridge/port/add bridge=HomeCPE-Bridge interface=wlan1')
SSH.Command('interface/bridge/port/add bridge=HomeCPE-Bridge interface=wlan2')
SSH.Command('ip/pool/add name=HomeCPE ranges=192.168.150.2-192.168.150.254')
SSH.Command('ip/address/add address=192.168.150.1 interface=HomeCPE-Bridge')
SSH.Command('ip/dhcp-server/add address-pool=HomeCPE interface=HomeCPE-Bridge disabled=no')
if __name__ == "__main__":
Run_App()