LoginSignup
5
5

More than 5 years have passed since last update.

snmpコマンドでipアドレス台帳を作成

Last updated at Posted at 2016-01-04

前提

取得先のサーバにsnmpがインストールされてあること
取得先のサーバのsnmpのコミュニティ名がわかること
ネットワーク内でコミュニティ名が統一されていること

snmpwalkでホスト名を取得

ホスト名はsnmpwalkを用いて取得する事ができる
1.3.6.1.2.1.1.5というMIBでhost名を取得できる。

command
$ snmpwalk -v 2c -c {community} {IP or host}  .1.3.6.1.2.1.1.5
SNMPv2-MIB::sysName.0 = STRING: serverA
$

serverAというホスト名ということがわかる。

台帳作成

192.168.10.0/24
192.168.11.0/24
から総当たりして接続可能なIPとhost名を取得。
ファイルに吐き出す。

(シンプルにawkで切り抜いても良かった。)

script.sh
#!/bin/sh

LOG="./ipscan.txt"
:>$LOG
for targetNW in 192.168.10. 192.168.20.;
do
        count=1
        while [ $count -le 255 ];
        do
                targetIP="$targetNW$count"
          echo $targetIP    `snmpwalk -v 2c -c {community}  $targetIP  .1.3.6.1.2.1.1.5 | sed -e "s/SNMPv2-MIB::sysName.0 = STRING://g"`   `snmpwalk -v 2c -c {community}  $targetIP  1.3.6.1.2.1.2.2.1.6 | sed -r "s/IF-MIB::ifPhysAddress.[0-9]+ = STRING://g" | grep -E *\:*\:*\:*\:*\: | uniq` >> $LOG;
                count=`expr $count + 1`
        done
done

よく使うOID情報

MIB名 OID 説明
sysName 1.3.6.1.2.1.1.5.0 ホスト名
sysDescr 1.3.6.1.2.1.1.1. HW・OS等
ipAdEntAddr 1.3.6.1.2.1.4.20.1.1.(*1) IPアドレス
ipAdEntNetMask 1.3.6.1.2.1.4.20.1.3.(*1) サブネットマスク
5
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5