Created
July 10, 2021 21:41
-
-
Save kido5217/64f9b75abc904a36a5831d8b6d2fd83f to your computer and use it in GitHub Desktop.
Generate cisco-like interfaces configuration file for ciscoconfparse and networkparse testing,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import sys | |
def gen_ip_addr() -> str: | |
ip_addr = ( | |
str(random.randrange(1, 255)) | |
+ "." | |
+ str(random.randrange(1, 255)) | |
+ "." | |
+ str(random.randrange(1, 255)) | |
+ "." | |
+ str(random.randrange(1, 255)) | |
) | |
return ip_addr | |
def gen_intf(idx: int) -> list: | |
intf_name = "interface GigabitEthernet0/1." + str(idx) | |
ip_addr_str = " ip address " + gen_ip_addr() + " 255.255.255.252" | |
misc_config = [ | |
" no ip route-cache", | |
" no ip proxy-arp", | |
" mtu 1500", | |
" speed 1000", | |
" no shutdown", | |
] | |
inft_config = [intf_name] | |
inft_config.extend(misc_config) | |
inft_config.insert(random.randrange(1, len(misc_config)), ip_addr_str) | |
return inft_config | |
inft_count = int(sys.argv[1]) | |
config_list = [] | |
for idx in range(1, inft_count + 1): | |
config_list.extend(gen_intf(idx)) | |
config_list.append("!") | |
config = "\n".join(config_list) | |
if len(sys.argv) < 3: | |
print(config) | |
else: | |
file_name = sys.argv[2] + "_" + sys.argv[1] + "_intf.config" | |
with open(file_name, "w") as outfile: | |
outfile.write(config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment