get IP without acessing the tcp/IP subsystem
`/sbin/ifconfig $if` =~ /inet addr:((\d{1,3}\.?){4})/m; $ipaddr = $1;

Replies are listed 'Best First'.
RE: IP address!
by merlyn (Sage) on Apr 26, 2000 at 01:14 UTC
    Bad! Never look at $1 unless you do it conditionally on the regex match. If the match fails, you get the previous regex match's $1.
      Thats a really good point, something that is kind of frustrating because it makes the code more complex. Also, note that ifconfig is a linux thing, not an NT thing... so this thing is not portable.
      $_ = `/sbin/ifconfig $if`; (/inet addr:((\d{1,3}\.?){4})/m) ? ($ipaddr = $1) : (warn 'ifconfig failed');
      I seem to remember there being a get function that does this too, but I can't remember it at the moment.
        NT DOES have ipconfig, however..
      I think also local may be used.
      { local $1; $string =~ m/(something)/; $found = $1; }