A
A
alxhtch2020-04-14 17:49:38
Automation
alxhtch, 2020-04-14 17:49:38

How to automate polling routers using scripts?

Gentlemen and ladies, good afternoon.

I happened to become a novice networker by chance (happy or not - I don’t understand yet) in one rather large company. I will warn you in advance - the experience is practically zero, therefore, obvious for experienced and experienced errors in the logic of the question are possible. Please don't get angry.
I faced such a task - in the possession and management of our telecommunications department there are about 1000 routers scattered within a radius of 200-300 km, Cisco 2811 and Huawei S2700, half of them also have a switch. From the TOR, it was found out that it was necessary to find out specifically which of the routers the switches are behind, to compare with the statement. It's kind of like an inventory. Physically, having traveled around the points, it is, of course, not possible to find out.
From what is given: tables with address pools of all routers, PuTTy and the boss's hope for my direct hands.
Manual connection was considered initially, but I started to go crazy from the monotony and monotony of actions at the end of the first day. The sequence of actions was as follows - Through putty, connect to the router, use commands to request the number of active ports and the number of machines on the network. Based on this ratio, it became clear that if there is one active port on the router, and there are several machines, it means that there is a switch behind it. Then you look at the statement - there is a switch in it, so everything is fine. If there is no switch after the router, but there is one in the statement, it’s bad. Mark and move on. It seems that everything is simple and logical, until you run into the total number of repetitions of this combination of actions.
After a diligent search, including in the foreign-language segment of the web, I came across a post with a script writing option like this:

for /f %%i in (devices.txt) do c:\putty\plink.exe [email protected]%%i -pw
P @55W0rD! -m command.txt >> log.txt

where in devices.txt all pools are stored in a column, cisco - login, [email protected]! - password, in command.txt commands in a column (in my case, two - show arp or display arp, show ip interface brief or display vlan brief, depending on whether it is a tsiska or a huawei), log.txt is actually a file for displaying everything you need . I throw in a batch file, I launch. And, of course, if it worked, then this long post would not exist. Commands do not pass, "Line has invalid autocommand" and that's it. Moreover, the pools from the file with devices are pulled out correctly, although two text files were created one after the other, and the logs are written.

And now, dear experts, a question.

This post has a lot of criticism in the comments, but maybe you can help me here? Is what I want to do generally doable? And if so, am I on the right track? I will accept all constructive advice, adequate criticism and help.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AUser0, 2020-04-14
@AUser0

I advise you to command plink in more detail, namely: specify the -v argument so that the program messages are more detailed. Specify -l cisco to be sure to log in as cisco. Don't forget to specify protocol -telnet and port -P 23 for the accuracy of the desired connection.
Total:

@echo off
for /f %%i in (devices.txt) do (
echo Fetching data from %%i...
c:\putty\plink.exe -telnet -P 23 -l cisco %%i -pw "P@55W0rD!" -m command.txt -v >>log.txt 2>&1
)

A
Armenian Radio, 2020-04-14
@gbg

I have a program that can telnet to a cisco, download ARP tables from it, compare them and draw a network diagram using graphviz. I can give the source code, now there are no resources for revision. MIT license.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question