Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

前提

取得先のサーバに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) サブネットマスク
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away