Afficher son @ IP

From Tuxunix
Jump to: navigation, search

Exemple


$ ./recupIp.pl
192.168.x.x


Code


   1.#! /usr/bin/perl -w
   2.     
   3.#
   4.#@Name recupIp.pl
   5.#@Note Affiche Addresse IP du poste
   6.#@Author Tuxedo
   7.#@Date 07/08/2007
   8.#@Brief
   9.#@Note
  10.#
  11.       
  12.     
  13.#
  14.#Affiche son ip
  15.#
  16.sub printIp(){
  17.       
  18.    my @ifconfig = (`/sbin/ifconfig`);
  19.       
  20.    for (@ifconfig){
  21.        #\s == caractere separateur <> \S caractere non espace
  22.        if(/^\s*inet add?r\s*:\s*(\S+)/){
  23.            ($1=~/127.+/) ? next : print("$1\n");
  24.        }
  25.    }
  26.       
  27.} #printIp
  28.       
  29.
  30.#     
  31.#Main
  32.#
  33.printIp();