Skip to content

Instantly share code, notes, and snippets.

@kamipo
Created February 11, 2015 04:07
Show Gist options
  • Save kamipo/6c7620da1b0638b3fece to your computer and use it in GitHub Desktop.
Save kamipo/6c7620da1b0638b3fece to your computer and use it in GitHub Desktop.
MySQLとか(Tokyo|Kyoto)ナントカのserver_idを計算するために使ってたコマンド
#!/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;
@kamipo
Copy link
Author

kamipo commented Feb 11, 2015

@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