Created
February 11, 2015 04:07
-
-
Save kamipo/6c7620da1b0638b3fece to your computer and use it in GitHub Desktop.
MySQLとか(Tokyo|Kyoto)ナントカのserver_idを計算するために使ってたコマンド
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -l | |
use strict; | |
use warnings; | |
$ENV{LANG} = "C"; | |
$ENV{PATH} ||= "/usr/local/bin:/usr/bin/:/bin"; | |
my $eth = shift || "eth0"; | |
`ip addr list dev $eth|grep 'inet '` =~ m{\.(\d+?)\.(\d+?)\/}; | |
print $1 * 1000 + $2; |
@dankogai ダメじゃないですよ!僕のユースケースでは第1オクテット第2オクテットが同じネットワーク構成上にDB等のミドルウェアサーバがいたのと、第3オクテット*1000 + 第4オクテットをserver_idとすると人間が見たときの見た目がIPと一致して人間がこのサーバーのserver_idはいくつになるべきかの検算がしやすかったのでこうしていました。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IPアドレスをそのままuint32_tとしてまるっと使っちゃうのはダメなの?