wanpoll

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2018 License: MIT Imports: 13 Imported by: 0

README

wanpoll

WAN IP をポーリングして監視し、変更を検知したら Route53Aレコード を書き換えるコマンドです。

一定間隔でIPアドレスを確認し、変更されている時のみ Route53 にAPI経由でレコードを書き換えます。

ルーターに一時的に接続できなくなった場合や Route53 のリクエストに失敗した場合は、標準エラー出力にエラーを出力しポーリングを継続します。

自宅のルーターが DDNS (Dynamic DNS) に対応していなかったため、ルーターの設定ページをハックして IP をぶっ抜いて動的なIPアドレスの変更を DNS に通知します。

対象

  • ソフトバンク光から支給された EWMTA2.1

http://172.16.255.254/GetWanIP.html にアクセスして WanIP をぶっこぬきます。

Install

パッケージマネージャーに dep を利用しています。

$ git clone https://github.com/kawasin73/wanpoll.git && cd wanpoll
$ dep ensure
$ go build

Example

$ ./wanpoll -hz xxxxxxxxxx -name=home.kawasin73.com,usa-reminder.kawasin73.com -user=xxxxxxxx -password=xxxxxxx -interval=10 -ttl=10
2018/07/11 23:00:23 detect new ip address "" -> "60.xxx.xxx.xxx"
2018/07/11 23:00:24 update record "home.kawasin73.com" == "60.xxx.xxx.xxx"
2018/07/11 23:00:24 update record "usa-reminder.kawasin73.com" == "60.xxx.xxx.xxx"

オプション

$ go build && ./wanpoll -h
Usage of ./wanpoll:
  -hz string
    	hosted zone Id in route53
  -interval int
    	interval time polling to routerIpPage (second) (default 1)
  -name string
    	recode name separated with ',' comma
  -password string
    	basic auth password for routerIpPage
  -region string
    	aws region where route53 is placed (default "ap-northeast-1")
  -ttl int
    	dns record ttl (second) (default 60)
  -url string
    	routerIpPage url which shows global wan ip address (default "http://172.16.255.254/GetWanIP.html")
  -user string
    	basic auth username for routerIpPage

AWS の Route53

wanpoll は AWS の Route53 にのみ対応しています。 Route53 の Hosted Zone のID を調べておく必要があります。

レコードの更新は、ChangeResourceRecordSets API を利用します。

認証

Route53 のリージョンは、オプションで設定します。

Route53 にアクセスする認証情報は、以下の3つの方法で設定できます。

  • EC2 の IAM role (自宅のソフトバンク光の環境から使うことを想定しているので、この方法は利用しないはずです)
  • shared credential file
  • 環境変数
    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY
    • AWS_SESSION_TOKEN (optional) (一時トークンは使うのは難しいので使わないと思います)

詳しくは以下の URL を参照してください。

権限

IAM には、インラインポリシーとして、以下のポリシーを追加します。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "<Sid>",
            "Effect": "Allow",
            "Action": [
                "route53:ChangeResourceRecordSets"
            ],
            "Resource": [
                "arn:aws:route53:::hostedzone/<zoneid>"
            ]
        }
    ]
}

参考URLは以下の通りです。

LICENSE

MIT

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL