1
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?

More than 3 years have passed since last update.

amazon-dashで、スキャンするNICを指定する方法

Last updated at Posted at 2020-12-27

amazon-dashでNICを明示的に指定

AmazonDashボタンをIoTボタン化するOSS, amazon-dashのTIPSである。

amazon-dashにて、discoveryもしくはrunする際、複数のNICが存在すると、意図しないNICのパケットを監視してしまう場合がある。
たとえば、eth0, eth1が存在する場合、AmazonDashボタンが接続されているNICがeth1である場合でも、eth0をスキャンしてしまう場合がある。
その場合、以下のTIPSにてスキャンするNICを明示的に指定する必要がある。

実行環境

以下の環境で実行した際の結果を使用した。

# cat /etc/debian_version 
10.7

# python --version
Python 2.7.16

# pip --version
pip 18.1 from /usr/lib/python2.7/dist-packages/pip (python 2.7)

# amazon-dash 
Welcome to Amazon-dash v1.4.0 using Python 2.7.16

discoveryでのNICの指定

discoveryを実行する場合、オプションでNICを指定可能である。

example

# amazon-dash discovery --interface eth1

Document

ヘルプに書いてあった

# amazon-dash discovery --help
Welcome to Amazon-dash v1.4.0 using Python 2.7.16
December 31 is the last day to block requests from your Amazon-dash buttons to Amazon servers. In 2020 your buttons can be bricked in an update from Amazon servers.
Usage: amazon-dash discovery [OPTIONS]

  Discover Amazon Dash device on network.

Options:
  --interface TEXT  Network interface.
  --help            Show this message and exit.

runでのNICの指定

run、もしくはサービス化(systemctlから起動)の場合、/etc/amazon-dash.ymlにて指定を行う。

example

settings:
  interface: eth1

Document

/etc/amazon-dash.ymlそのものに記載は無いが、ソースコード内で確認が出来る。
該当のファイルは、config.pyで、JSONのスキーマで存在を確認出来る。


18:#: Json-schema validation
19:SCHEMA = {
20:    "title": "Config",
21:    "type": "object",
22:    "properties": {
23:        "settings": {
24:            "type": "object",
25:            "properties": {
26:                "delay": {
27:                    "type": "integer"
28:                },
29:                "interface": {
30:                    "type": "string"
31:                },

NICの名前について

NICの名前そのものはamazon-dash内では特にバリデーションをしておらず、そのままscan.pyscan_devicesに渡しているだけのようである。
要には、OSが認識できていれば、なんでも良いらしい。
物理NICの他、VLAN Interface(例:eth1.100)でも正常に動作をしている。

試しに、無効なインターフェース名を渡したところ、こんな感じのエラーを吐いて止まった。
NIC周りを変更した後にトラブルになった際は、参考にして欲しい。

# amazon-dash discovery --interface foo                             
Welcome to Amazon-dash v1.4.0 using Python 2.7.16

(snip)

OSError: foo: No such device exists (SIOCGIFHWADDR: No such device)
Exception IOError: IOError(19, 'No such device') in <bound method L2ListenSocket.__del__ of <scapy.arch.linux.L2ListenSocket object at 0xb6744f0c>> ignored

# echo $?
1
1
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
1
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?