sark
sark

Reputation: 81

Python Network Projects

I originally posted on his on Network Engineering but it was suggested that o post it on here. I've been learning Python and since I work in networking I'd like to start writing a few scripts that I can use in my day to day work tasks with switches. So my question is this, what network projects have you used python in? What sort of tasks have you written scripts for? I'm not asking for source code, I'm interested in what projects people have done to inspire my own coding adventures!

Thanks all!

Upvotes: 0

Views: 495

Answers (2)

Mert Kulac
Mert Kulac

Reputation: 294

One of the most enjoyable parts of this job is parceling out data on network devices. I suggest you search for Netmiko-TTP module along with SSH connection to start. I have shared my sample code below.

            from pprint import pprint
            from ttp import ttp
            import json
            import time
            
            with open("showSystemInformation.txt") as f:
               data_to_parse = f.read()
            
            ttp_template = """
            <group name="Show_System_Information">
            System Name            : {{System_Name}}
            System Type            : {{System_Type}} {{System_Type_2}}
            System Version         : {{Version}}
            System Up Time         : {{System_Uptime_Days}} days, {{System_Uptime_HR_MIN_SEC}} (hr:min:sec)
            Last Saved Config      : {{Last_Saved_Config}}
            Time Last Saved        : {{Last_Time_Saved_Date}} {{Last_Time_Saved_HR_MIN_SEC}}
            Time Last Modified     : {{Last_Time_Modified_Date}} {{Last_Time_Modifed_HR_MIN_SEC}}
            </group>
            """
            
            parser = ttp(data=data_to_parse, template=ttp_template)
            parser.parse()
            
            # print result in JSON format
            results = parser.result(format='json')[0]
            print(results)
            [appadmin@ryugbz01 Nokia]$ python3 showSystemInformation.py
            [
                {
                    "Show_System_Information": {
                        "Last_Saved_Config": "cf3:\\config.cfg",
                        "Last_Time_Modifed_HR_MIN_SEC": "11:46:57",
                        "Last_Time_Modified_Date": "2022/02/09",
                        "Last_Time_Saved_Date": "2022/02/07",
                        "Last_Time_Saved_HR_MIN_SEC": "15:55:39",
                        "System_Name": "SR7-2",
                        "System_Type": "7750",
                        "System_Type_2": "SR-7",
                        "System_Uptime_Days": "17",
                        "System_Uptime_HR_MIN_SEC": "05:24:44.72",
                        "Version": "C-16.0.R9"
                    }
                }
            ]

Upvotes: 0

ddevalco
ddevalco

Reputation: 1249

Backing up and copying configs to server. Automate certain config changes to adhere to standards. Scripts to copy run start on all devices at will. Finding various config entries on all devices that may need to be altered.

There are so many possibilities.

Search github and pastebin and the overflow sites for anything using:

Import netmiko Import paramiko Import ciscoconfparse

Scripts using any of those libraries will be network related typically and offer up ideas.

Upvotes: 0

Related Questions