105 lines
3.2 KiB
Python
105 lines
3.2 KiB
Python
RSA_BITSIZE = 2048
|
|
MANAGEMENT_INTERFACE = 'GigabitEthernet 2'
|
|
|
|
|
|
def generate_config(s):
|
|
"""
|
|
De volgende waarden moeten in een tuple meegegeven worden.
|
|
HOSTNAME DOMAIN SSH_USERNAME SSH_PASSWORD ENABLE_PASSWORD MANAGEMENT_IP MANAGEMENT_MASK
|
|
"""
|
|
config = 'enable\n' \
|
|
'configure terminal\n' \
|
|
f"hostname {s['HOSTNAME']}\n" \
|
|
f"ip domain name {s['DOMAIN']}\n" \
|
|
f"crypto key generate rsa modulus {RSA_BITSIZE}\n" \
|
|
f"username {s['SSH_USERNAME']} privilege 15 password {s['SSH_PASSWORD']}\n" \
|
|
f"enable secret {s['ENABLE_PASSWORD']}\n" \
|
|
'service password-encryption\n' \
|
|
'ip ssh version 2\n' \
|
|
f"interface {MANAGEMENT_INTERFACE}\n" \
|
|
f"ip address {s['MANAGEMENT_IP']} {s['MANAGEMENT_MASK']}\n" \
|
|
f"ipv6 address {s['MANAGEMENT_IPv6']}\n" \
|
|
'no shutdown\n' \
|
|
'exit\n' \
|
|
'line console 0\n' \
|
|
'login local' \
|
|
'line vty 0 15\n' \
|
|
'transport input ssh\n' \
|
|
'login local\n' \
|
|
'end\n' \
|
|
'exit\n'
|
|
return config
|
|
|
|
|
|
def ask_options():
|
|
opt = dict()
|
|
|
|
opt['HOSTNAME'] = input('Hostname: ')
|
|
while not opt['HOSTNAME']:
|
|
print('Hostname required!')
|
|
opt['HOSTNAME'] = input('Hostname: ')
|
|
|
|
opt['DOMAIN'] = input('Domain(hu.lan): ')
|
|
if not opt['DOMAIN']:
|
|
opt['DOMAIN'] = 'hu.lan'
|
|
|
|
opt['SSH_USERNAME'] = input('SSH Username(cisco): ')
|
|
if not opt['SSH_USERNAME']:
|
|
opt['SSH_USERNAME'] = 'cisco'
|
|
|
|
opt['SSH_PASSWORD'] = input('SSH Password(cisco): ')
|
|
if not opt['SSH_PASSWORD']:
|
|
opt['SSH_PASSWORD'] = 'cisco'
|
|
|
|
opt['ENABLE_PASSWORD'] = input('Enable Password(class): ')
|
|
if not opt['ENABLE_PASSWORD']:
|
|
opt['ENABLE_PASSWORD'] = 'class'
|
|
|
|
opt['MANAGEMENT_IP'] = input('Management IP: ')
|
|
while not opt['MANAGEMENT_IP']:
|
|
print('Address required!')
|
|
opt['MANAGEMENT_IP'] = input('Management IP: ')
|
|
|
|
opt['MANAGEMENT_MASK'] = input('Management Mask(255.255.255.0): ')
|
|
if not opt['MANAGEMENT_MASK']:
|
|
opt['MANAGEMENT_MASK'] = '255.255.255.0'
|
|
|
|
opt['MANAGEMENT_IPv6'] = input('Management IPv6/netmask: ')
|
|
while not opt['MANAGEMENT_IPv6']:
|
|
print('Address required!')
|
|
opt['MANAGEMENT_IPv6'] = input('Management IPv6: ')
|
|
|
|
return opt
|
|
|
|
|
|
def menu():
|
|
print(
|
|
f"{'_' * 64}\n"
|
|
'Static variabelen(pas script aan):\n'
|
|
f' SSH RSA key bitsize: {RSA_BITSIZE}\n'
|
|
f' Management interface: {MANAGEMENT_INTERFACE}\n'
|
|
f"{'_' * 64}\n"
|
|
f'q: quit\n'
|
|
f'g: generate config\n'
|
|
f"{'_' * 64}"
|
|
)
|
|
|
|
chosen = input('option: ')
|
|
|
|
if chosen == 'q':
|
|
exit()
|
|
elif chosen == 'g':
|
|
print(f"{'_' * 64}\n")
|
|
options = ask_options()
|
|
config = generate_config(options)
|
|
print(f"copy paste the config below to the router, this config wil be saved to: {options['HOSTNAME']}.conf")
|
|
print(f"{'_' * 64}\n")
|
|
print(config)
|
|
print(f"{'_' * 64}\n")
|
|
with open(f"{options['HOSTNAME']}.conf", 'w') as file:
|
|
file.writelines(config)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
menu()
|