In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Through the previous three experiments, we have been able to use python to operate cisco devices through telnet, and then start a new phase of experiments.
Experimental purpose: network inspection, and then store the information in the database
This experiment needs to expand the new topology again, and the experimental environment is changed to ubuntu, and the subsequent expansion will be done in the linux environment. The local address is 10.10.10.142, and six routers are controlled by two management switches and their addresses are assigned
R1
10.10.10.101
R2
10.10.10.102
R3
10.10.10.103
R4
10.10.10.104
R5
10.10.10.105
R6
10.10.10.106
Configure an IP address for each Devic
Due to the need for batch configuration, you can use the global send function of CRT to deploy batch commands.
After all the vty is deployed, three devices will be opened to reduce the machine burden, and then further development will be carried out.
Verify connectivity
Found a list of neighbors
Verify the execution results of the code
The next task is to grab packets by the system and analyze these packets. Our task is to record the neighbor relationship in the form of grabbing cdp packets, and send an alarm message if the neighbor relationship changes.
Let's talk about the idea here: get the accepted string and process the information, that is, only receive R1 Fas0/0 Fas0/0 and store it in the local database, so you need to set up a neighbor table in the database to store the router number, the local connection number and the port number. Here two databases are installed and stored in two places, one is disaster preparedness, the other is to do experiments later to test the difference in running efficiency between relational database and non-relational database.
Step 1: intercept information
Process this string of characters:
'show cdp neighbors\ r\ nCapability Codes: r-Router, T-Trans Bridge, B-Source Route Bridge\ r\ nS-Switch, H-Host, I-IGMP, r-Repeater\ r\ n\ r\ nDevice ID Local Intrfce Holdtme Capability Platform Port ID\ r nR1 Fas0/0 172nd R S I 3640 Fas0/0\ r\ nR6 Fas0/0 144R S I 3640 Fas0/0\ r\ nR4 Fas0/0 170R S I 3640 Fas0/0\ r\ nR2 >'
The string processing method you plan to use this time is slicing, and you can also try a method similar to regular expressions later.
Waiting for 2 seconds is the neighbor information returned by the receiving device.
The processing is finished, and it's very nice.
Step 2: design the relationship table and build the table
Design mysql
Database:NDB
Table:cdp_nei
RID
Char
Local_Int
Char
Port_ID
Char
First_record
Datetime
Change_record
Datetime
Here, a table has been established in ndb in mysql, which stores the information of cdp neighbors. Based on the current topology, it can be predicted that when all routers are running, the information entry in the table should be 6-7-42.
First_record is used to record the time when the data item was first recorded, while Change_record automatically records the time each time the data item is modified. When querying, you can check the time when the data item is modified. If there is a change, you can directly prompt the link to jitter.
Step 3: write to the database
Let's have an interview in the debugging world. The order can be passed.
View the effect
After that, you can write relevant instructions in the code, but before you do that, do an exciting thing: wear clothes and pants before you run away!
Code:
This is the initial version, which is later encapsulated in a separate class for development convenience
After writing, remember to synchronize the data before you can find the relevant information in the database.
Write success and enjoy it.
Step 4: traverse the neighbor information of all devices
Idea: log in to each device by telnet, use show cdp nei on it, and then collect the peer port information and write it to the database
Here we can dynamically store the information in the database. In the next experiment, we will alert the error information by writing a script.
Notes on the installation tutorial for python-mysql and the use of the mysqldb toolkit link in the comments
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.