Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to run a quick network device inventory UNIX
I've written a script that I call netinv which uses the ARP cache to identify devices on the network segment. For each device, it looks up the vendor name based on the MAC address and also tries to get the remote system's netbios name. For small (i.e. home) networks, the vendor and netbios name are usually enough to remind you what a particular device is.

To use it, start by downloading the script from my page; you can do this in the Terminal by typing:
  curl -O 'http://www.studiosells.net/msells/netinv'
Once downloaded, move it to a directory on your path and make it executable with chmod a+rx ./netinv (assuming you're in that directory). Read the rest of the hint for some sample output and further explanations on how the tool works.

Sample Output:
$ ./netinv
IP               MAC                    DNSname         NBname          Vendor          
----------       ----------             ----------      ----------      ----------      
192.168.3.1      0:a0:c5:e2:4a:16       ?                               ZYXEL COMMUNICATION
192.168.3.3      0:0:39:8:4:1a          ?               PIZZA           TOSHIBA CORPORATION
192.168.3.4      0:4:e2:52:4e:11        dell            CANADA          SMC Networks, Inc.
192.168.3.40     0:50:e4:99:2c:39       meatloaf        MEATLOAF        APPLE COMPUTER, INC.
192.168.3.52     0:b:db:a7:4c:5         ?               STACY           Dell ESG PCBA Test
192.168.3.60     0:4:76:da:47:1d        dell            DELL            3 Com Corporation
192.168.0.110    00:03:93:bf:17:c0      eyeBook         EYEBOOK         Apple Computer, Inc.
192.168.3.200    0:3:93:bd:26:1e        fatmac          FATMAC          Apple Computer, Inc.
Notes:
  1. Since this works from your ARP table it will only include hosts that you've ARPed for:

    • The host you run it on will not be included. I considered this a big enough non-feature that you can specify the -l option to have the the local system included. The code for doing this is quite sketchy, but I didn't want to add more module requirements.

    • You can ping hosts to get them added to your ARP table, or one way to quickly populate is to do a scan of some sort.

      • Assuming you have nmap installed, just do nmap -sP 192.168.0.0/24
      • If you don't nave nmap, here's a slower method:
        perl -e 'for $i (1..10) { system qq!nc -z -w 1 192.168.0.$i 22!; }'
        Note that port 22 does not have to be open on the system. I just found that using nc was faster than using ping -c 1.

  2. There are command line options to disable the vendor and netbios lookups, as well as to produce non-justified tab separated output without the header. See netinv -h for details.

  3. If you don't have the Perl module Net::MAC::Vendor, then netinv will use a built-in vendor lookup that seems to work OK, but is probably not as robust. Try installing the module with perl -MCPAN -e 'install Net::MAC::Vendor'. There's also a web page where you can do MAC-to-vendor lookups.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[30,354 views]  

A script to run a quick network device inventory | 22 comments | Create New Account
Click here to return to the 'A script to run a quick network device inventory' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to run a quick network device inventory
Authored by: rajulkabir on Oct 13, '04 12:15:45PM

1) I couldn't get NET::MAC::Vendor to build - it died on the fetch_oui test with 'syntax error at t/fetch_oui.t line 20, near "$oui ( "' and 'syntax error at t/fetch_oui.t line 28, near "}"'. Did anyone else have that problem?

2) I think what this script is missing to put it over the edge into really cool territory is to (either by default or as an option) look at the routing table to figure out the locally connected subnets on its own and broadcast ping them all to flesh out the ARP table.



[ Reply to This | # ]
module build
Authored by: ssevenup on Oct 13, '04 12:51:11PM

1) Same here

2) Agreed

--MM

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]
A script to run a quick network device inventory
Authored by: macubergeek on Oct 14, '04 06:03:16AM

I installed via the CPAN perl module

cpan> force install NET::MAC::Vendor
worked fine



[ Reply to This | # ]
nope I was wrong
Authored by: macubergeek on Oct 14, '04 06:09:44AM

Running make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/compile..................NOK 1# Failed test (t/compile.t at line 7)
# Tried to use 'Net::MAC::Vendor'.
# Error: Can't locate LWP/Simple.pm in @INC (@INC contains: /private/var/root/.cpan/build/Net-MAC-Vendor-0.21/blib/lib /private/var/root/.cpan/build/Net-MAC-Vendor-0.21/blib/arch /usr/local/lib/perl5/5.8.5/darwin-2level /usr/local/lib/perl5/5.8.5/darwin-2level /usr/local/lib/perl5/5.8.5 /usr/local/lib/perl5/site_perl/5.8.5/darwin-2level /usr/local/lib/perl5/site_perl/5.8.5/darwin-2level /usr/local/lib/perl5/site_perl/5.8.5 /usr/local/lib/perl5/site_perl/5.8.5/darwin-2level /usr/local/lib/perl5/site_perl/5.8.5 /usr/local/lib/perl5/site_perl . /usr/local/lib/perl5/5.8.5/darwin-2level /usr/local/lib/perl5/5.8.5 /usr/local/lib/perl5/site_perl/5.8.5/darwin-2level /usr/local/lib/perl5/site_perl/5.8.5 /usr/local/lib/perl5/site_perl .) at /private/var/root/.cpan/build/Net-MAC-Vendor-0.21/blib/lib/Net/MAC/Vendor.pm line 50.
# BEGIN failed--compilation aborted at /private/var/root/.cpan/build/Net-MAC-Vendor-0.21/blib/lib/Net/MAC/Vendor.pm line 50.
# Compilation failed in require at (eval 1) line 2.
FAILED--Further testing stopped: Could not compile Net::MAC::Vendor.
make: *** [test_dynamic] Error 2
/usr/bin/make test -- NOT OK
Running make install
make test had returned bad status, won't install without force

cpan> # Looks like you failed 1 tests of 1.

module wouldn't install



[ Reply to This | # ]
A script to run a quick network device inventory
Authored by: demmons65 on Oct 13, '04 01:07:34PM

Checking if your kit is complete...
Looks good
Writing Makefile for Net::MAC::Vendor
cp lib/Vendor.pm blib/lib/Net/MAC/Vendor.pm
Manifying blib/man3/Net::MAC::Vendor.3
/usr/bin/make -- OK
Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/compile..................NOK 1# Failed test (t/compile.t at line 7)
# Tried to use 'Net::MAC::Vendor'.
# Error: Can't locate LWP/Simple.pm in @INC (@INC contains: /Users/dave/.cpan/build/Net-MAC-Vendor-0.21/blib/lib /e
# BEGIN failed--compilation aborted at /Users/dave/.cpan/build/Net-MAC-Vendor-0.21/blib/lib/Net/MAC/Vendor.pm line 50.
# Compilation failed in require at (eval 1) line 2.
FAILED--Further testing stopped: Could not compile Net::MAC::Vendor.
make: *** [test_dynamic] Error 2
/usr/bin/make test -- NOT OK
Running make install
make test had returned bad status, won't install without force
# Looks like you failed 1 tests of 1.

Very strange. I think I'm going to dump the build of Tiger I'm running. Seems like lots of things are ready tow ork with it yet.


---
d a v e

http://www.hostwerks.com/~dave/



[ Reply to This | # ]
A script to run a quick network device inventory
Authored by: avarame on Oct 13, '04 04:23:05PM

Same results, 10.3.5



[ Reply to This | # ]
FIX
Authored by: avarame on Oct 13, '04 04:26:17PM

For some reason, Net::MAC::Vendor depends on LWP::Simple, but doesn't error if LWP::Simple isn't installed (probably because it only needs it for (nonessential) tests). Just run install LWP::Simple first, and follow all its dependencies.



[ Reply to This | # ]
FIX
Authored by: timhaigh on Oct 13, '04 05:19:41PM

Sorry to say your fix doesn't work for me on 10.3.5.

I get this error.

Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/compile..................ok
t/extract_oui_from_html....ok
t/fetch_oui................"my" variable $oui masks earlier declaration in same statement at t/fetch_oui.t line 22.
syntax error at t/fetch_oui.t line 20, near "$oui ( "
syntax error at t/fetch_oui.t line 28, near "}"
Execution of t/fetch_oui.t aborted due to compilation errors.
# Looks like your test died before it could output anything.
t/fetch_oui................dubious
Test returned status 255 (wstat 65280, 0xff00)
DIED. FAILED tests 1-7
Failed 7/7 tests, 0.00% okay
t/normalize_mac............ok
t/parse_oui................ok
t/pod......................skipped
all skipped: Test::Pod 1.00 required for testing POD
Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
t/fetch_oui.t 255 65280 7 14 200.00% 1-7
1 test skipped.
Failed 1/6 test scripts, 83.33% okay. 7/22 subtests failed, 68.18% okay.
make: *** [test_dynamic] Error 2
/usr/bin/make test -- NOT OK
Running make install
make test had returned bad status, won't install without force



[ Reply to This | # ]
FIX ... Not!!
Authored by: ssevenup on Oct 13, '04 08:28:00PM

Same here on 10.3.5

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]
A script to run a quick network device inventory
Authored by: soulrider2k on Oct 13, '04 04:27:28PM

Same error here on 10.3.5


Any clues?

---
soulrider2k



[ Reply to This | # ]
force install
Authored by: sfederman on Oct 13, '04 10:07:54PM

I force installed Net::MAC::Vendor, and it appears to work fine...



[ Reply to This | # ]
force install
Authored by: uurf on Oct 13, '04 10:19:17PM

how'd you do that? It wouldn't go for it even after su'ing to root.



[ Reply to This | # ]
force install
Authored by: sfederman on Oct 14, '04 12:39:21AM

I didn't do anything special, I just was able to sudo cpan, then force install Net::MAC::Vendor. This worked for me on 2 different systems, each of which have 10.3.5 installed...



[ Reply to This | # ]
force install
Authored by: Poolart on Oct 14, '04 04:56:00AM

Please tell us the command line you use, to force install



[ Reply to This | # ]
force install
Authored by: sfederman on Oct 14, '04 04:35:56PM
Here's what I typed

$ sudo cpan
cpan> force install Net::MAC::Vendor

I've already done this, so I cannot show you the install log. Unfortunately, I did not save it...

[ Reply to This | # ]

A script to run a quick network device inventory
Authored by: artychim on Oct 13, '04 03:16:56PM

Worked as advertized for me, except that since I didn't have the Net::MAC::Vendor module, the script got it for me.
Thanks
will try it at work tomorrow

Arthur



[ Reply to This | # ]
A script to run a quick network device inventory
Authored by: andyinindy on Oct 14, '04 10:56:10AM
I was able to get NET::MAC::Vendor to install by downloading it and manually compiling it. Grab it here.

gunzip, tar -xvf, cd to the Net-MAC-Vendor-0.21 folder. Then, perl Makefile.PL, make, sudo make -i -k install. Note the -i (ignore) and -k (keep going) flags.

Worked for me!

[ Reply to This | # ]
A script to run a quick network device inventory
Authored by: inextenza on Oct 14, '04 05:13:30PM

inox ~/Desktop/Downloads/Net-MAC-Vendor-0.21> sudo make -i -k install
Password:
Installing /Library/Perl/5.8.1/Net/MAC/Vendor.pm
Installing /man/man3/Net::MAC::Vendor.3
Writing ///Library/Perl/5.8.1/darwin-thread-multi-2level/auto/Net/MAC/Vendor/.packlist
Appending installation info to ///System/Library/Perl/5.8.1/darwin-thread-multi-2level/perllocal.pod
inox ~/Desktop/Downloads/Net-MAC-Vendor-0.21> cd -
~/Desktop
inox ~/Desktop> ./netinv.pl
You don't have the Net::MAC::Vendor module - ./netinv.pl will use it's own feeble version.
^C

snif :-(

So, why my Airport Extreme Base Station isn't listed? (tested from a Laptop connected on it by WiFi, and a linux box connected on a switch)?



[ Reply to This | # ]
A script to run a quick network device inventory
Authored by: andyinindy on Oct 15, '04 10:13:08AM
Writing ///Library/Perl/5.8.1/darwin-thread-multi-2level/auto/Net/MAC/Vendor/.packlist
Appending installation info to ///System/Library/Perl/5.8.1/darwin-thread-multi-2level/perllocal.pod


Maybe I just wasn't paying attention when I compiled this, but the pathnames above look pretty screwed up. "///System/Library/...." ?? What's the deal with the triple slashes?

Hope I'm not showing my ignorance here.

I also noticed that forcing an install in this manner leaves you with a stray "Man" folder at the root of the drive. I just deleted it.

Sorry this didn't work for you!

[ Reply to This | # ]
make: command not found
Authored by: chancer on May 30, '06 08:28:49PM

Hi, ignorant question. So is the make command also something I need to
download and install? If so could you point me to it? I'd appreciate it
greatly.



[ Reply to This | # ]
make: command not found
Authored by: chancer on May 30, '06 08:36:54PM

Never mind, I googled and found I have to install the developer tools. I
really didn't want a gig and a half of stuff on my drive, so I may not do
it. It would be cool to find a standalone package, if there is such a thing.

I also realized this tip is so old that no one is likely reading the
comments any more. Oh well.



[ Reply to This | # ]
A script to run a quick network device inventory
Authored by: eduo on Oct 15, '04 01:37:41PM

Keep in mind that ARP has a memory leak that makes the systems unstable after they've been hit for a while. A friend of mine developed a tool like this for the office and the machine he was using it on became unusable after a week or so of constant polling.

Eduo

---
Eduo



[ Reply to This | # ]