]> git.nbdom.net Git - nb.git/commitdiff
bin/ovh-api
authorroot <sys@15gifts.com>
Mon, 31 Jul 2017 11:48:48 +0000 (12:48 +0100)
committerroot <sys@15gifts.com>
Mon, 31 Jul 2017 11:48:48 +0000 (12:48 +0100)
bin/ovh-api

index 26caf00956eafc7f49117f4736cad0a597bab37e..f1a411954520ab4ff37c52067b4f95f67276c6cd 100755 (executable)
@@ -55,6 +55,11 @@ init();
 open STDOUT,'| (which jq > /dev/null && jq . || cat)' if $Opt{jq};
 my $Api = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $KEY[0], applicationSecret => $KEY[1], consumerKey => $KEY[2]);
 
+if ($Opt{'show-ips'}) {
+  print map {"$_\n"} ips();
+  exit;
+}
+
 # Auth
 auth() if @KEY < 3;
 
@@ -178,9 +183,9 @@ sub ip_routed {
   return wantarray ? @routed : \@routed;
 }
 
-sub ips() {
-  return grep { defined } map {
-    /^\s*inet.*?([\d\.]+)/ and $1 ne "127.0.0.1"
+sub ips {
+  return grep { defined $_ and $_ ne ""} map {
+    /^\s*inet.*?([\d]+\.[\d]+\.[\d]+\.[\d]+)/ and $1 ne "127.0.0.1"
     ? $1
     : undef
   } `ip addr show || ifconfig`;
@@ -590,6 +595,7 @@ $NAME - Script to query ovh's api
  option[ip-routed=s] Print where is routed an ip
  option[ip-is-routed=s] Exit 0 if ip is routed to this host, 2 if slave
  option[sql]         Produce sql to update a database
+ option[show-ips]    Print local ips
 
  option[verbose|v+] Verbose mode: increase the verbosity level.
  option[debug+]     Debug mode: increase the verbosity level.