136 |
rodolico |
1 |
v3.0.1
|
9 |
rodolico |
2 |
|
5 |
rodolico |
3 |
This script polls network switch ports to see which MAC addresses are assigned to them, then polls the arp table
|
|
|
4 |
on one or more routers to determine the IP address. It then uses reverse DNS to look up the name of the device
|
|
|
5 |
|
33 |
rodolico |
6 |
The script requires snmp to be installed (no MIB files required), and uses the perl module YAML::Tiny. On a Debian based
|
|
|
7 |
system, this can be installed with the command:
|
|
|
8 |
|
|
|
9 |
apt-get libyaml-tiny-perl snmp
|
|
|
10 |
|
5 |
rodolico |
11 |
The results are saved in a YAML file and used to initialize the internal structures if it exists, so when a device
|
136 |
rodolico |
12 |
goes off the network, the information that it was there remains available (and the date/time it was last seen). As of v3.0.1
|
|
|
13 |
this can be modified with the 'ttl' entry in the configuration, ie 'ttl: 4d' will remove an entry if it has not been seen for
|
|
|
14 |
4 days.
|
5 |
rodolico |
15 |
|
136 |
rodolico |
16 |
Since the data is stored in a YAML file, a second script, mapSwitchesCSV .pl was created to convert to a tab delimited text
|
5 |
rodolico |
17 |
file for human viewing and/or script processing.
|
|
|
18 |
|
136 |
rodolico |
19 |
There is also a script, csv2html which will convert the csv file (actually, tsv) to an HTML table embedded in a static web
|
|
|
20 |
page, optionally with some titles and a css file.
|
|
|
21 |
|
|
|
22 |
All three executables (mapSwitches, mapSwitchesCSV.pl, csv2html) respond to --help with a brief description
|
|
|
23 |
|
5 |
rodolico |
24 |
Files:
|
|
|
25 |
|
136 |
rodolico |
26 |
mapSwitches - the main file which connects to each device in config, gathers data, and updates persistent storage
|
33 |
rodolico |
27 |
mapSwitchesCSV.pl - converts stored data into a CSV (default is tab delimited)
|
5 |
rodolico |
28 |
mapswitches.cron - sample cron file to gather information hourly and generate a CSV once a day
|
136 |
rodolico |
29 |
mapswitches.css - sample csv file
|
|
|
30 |
csv2html - reads a tsv/csv file and emits a static web page with data shown in tabular format
|
5 |
rodolico |
31 |
|
|
|
32 |
The following files are not required for the system to run
|
|
|
33 |
mapSwitches.config.yaml.sample - sample configuration file
|
|
|
34 |
README - This file
|
|
|
35 |
makeConfig.pl.sample - generate configuration file from hash. Easier for perl programmers
|
|
|
36 |
pingall.pl - utility to ping all available ports on a /24 network. Used to artificially refresh arp table
|
|
|
37 |
|
|
|
38 |
The configuration file MUST be created before running the script. It can be manually created
|
|
|
39 |
(rename mapSwitches.config.yaml.sample to mapSwitches.config.yaml and edit) or generated makeConfig.pl.sample
|
|
|
40 |
(edit hash, then run)
|
|
|
41 |
|
|
|
42 |
The following file is created on first run.
|
|
|
43 |
mapSwitches.yaml
|
|
|
44 |
This is the persistent storage. It can be safely deleted at any time to reinitialize the system.
|
|
|
45 |
|
|
|
46 |
We generally set this to be run hourly, and we then generate a tab delimited text file once a day. See the sample cron file
|
|
|
47 |
for how we do it.
|
7 |
rodolico |
48 |
|
|
|
49 |
Script does not need any special permissions so can be run as any user.
|
|
|
50 |
|
33 |
rodolico |
51 |
mapSwitchesCSV.pl accepts two positional parameters. The first is the delimiter for the output, the second is a character to
|
|
|
52 |
encapsulate the columns. Default is a tab for delimiter and no encapsulation.
|
|
|
53 |
|
66 |
rodolico |
54 |
Tested under Devuan Jessie, connecting to HP Procurve and OpnSense router, and on HP A5120 with IPFire router
|