2
0

More than 3 years have passed since last update.

Pythonで最新のMACアドレスベンダーDBをoui.txtから生成する

Last updated at Posted at 2019-12-02

はじめに

  • MACアドレスは機器固有のものであり、識別するのに便利
  • MACアドレスの最初の6桁はベンダーコードといい製造メーカーのIDになっている
  • IEEEが管理していて、IEEEのサイトで調べることができる

やりかた

以下のIEEEのページからベンダー一覧をダウンロード

あとは以下の動けばいいコードを実行するとMACアドレス6桁がキーの辞書型が出来上がります。

data = {}
with open('oui.txt') as f:
    i = 0
    for s_line in f:
        i = i + 1
        if i < 5:
            continue
        p = i % 6
        if p == 0:
            mac = s_line.split("     (base 16)\t\t")[0].strip("\n")
            inc = s_line.split("     (base 16)\t\t")[1].strip("\n")
            data[mac] = [inc]
            if inc == "Private":
                i = i + 3
        if p == 3:
            ccltd = s_line.strip()
            data[mac].append(ccltd)         


print(data["000C29"])

実行結果

[root@pc python]# python3 mac.py 
['VMware, Inc.', 'US']

あとはjsonにするなり、DBに格納するなり自由に

おわりに

 検索できるサイトはあってもローカルで保持したい場合とかはあると思うので(あったので)

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