0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Aruba AP の BSSID を取得

Last updated at Posted at 2024-10-25

Aruba の BSSID を取得するスクリプト

台数が多いと確認が大変なのでスクリプトにしてみた。
python は使ったことがないので動けば正義です。

netmiko って何も考えなくて使えるの素晴らしいですね。

aruba-bssid
#!/usr/bin/python3

from netmiko import ConnectHandler
import re

def get_bssid(host, user, passwd):
  aruba_ap = {
    "device_type": "aruba_os",
    "host": host,
    "username": user,
    "password": passwd,
  }

  with ConnectHandler(**aruba_ap) as net_connect:
    # print(f'////  {host} に接続しました ////')
    # print(net_connect.find_prompt())

    output = net_connect.send_command("show ap bss-table")
    for line in output.splitlines():
      # 関係ない行はスキップ
      if not re.search(r'^(..:){5}.. ',line):
        continue

      re_str = re.search(r'^(..:..:..:..:..:..)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)',line)

      bssid   = re_str.group(1)
      ssid    = re_str.group(2)
      ip_addr = re_str.group(4)
      band    = re_str.group(5).split('/')[0]
      channel = re_str.group(6).split('/')[0]
      name    = re_str.group(9)
      print(f'{name}, {ssid}, {bssid}, {band}, {channel}')

    net_connect.disconnect()


# main
if __name__=="__main__":
  # ここに接続先、ユーザ名、パスワードを設定
  hosts = {
    '192.168.33.1' : {'user' : 'admin', 'passwd' : 'pass'},
    '192.168.33.2' : {'user' : 'admin', 'passwd' : 'pass'},
  }

  print('name, ssid, bssid, band, channel')
  for host, var in hosts.items():
    get_bssid(host, var['user'], var['passwd'])

出力は stdout にカンマ区切りで出力されます。ファイルにリダイレクトして csv ファイルにすると扱いやすいでしょう。

実行例
$ python ./aruba-bssid
name, ssid, bssid, band, channel
AP-01, Guest, aa:aa:aa:bb:bb:32, 5GHz, 140+
AP-01, test, aa:aa:aa:bb:bb:33, 5GHz, 140+
AP-01, alpha, aa:aa:aa:bb:bb:34, 5GHz, 140+
AP-01, Guest, aa:aa:aa:bb:bb:22, 2.4GHz, 6
AP-01, test, aa:aa:aa:bb:bb:23, 2.4GHz, 6
AP-01, alpha, aa:aa:aa:bb:bb:24, 2.4GHz, 6
AP-02, test, aa:bb:cc:dd:ee:53, 5GHz, 60+
AP-02, alpha, aa:bb:cc:dd:ee:54, 5GHz, 60+
AP-02, Guest, aa:bb:cc:dd:ee:42, 2.4GHz, 1
AP-02, test, aa:bb:cc:dd:ee:43, 2.4GHz, 1
AP-02, alpha, aa:bb:cc:dd:ee:44, 2.4GHz, 1
AP-02, Guest, aa:bb:cc:dd:ee:52, 5GHz, 60+
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?