Tim Wolak wrote:
>
> I am writing a script to monitor a file and if a line is matched write
> it to a file, then grab the IP address from that line and write it to
> another file.  As I'm ok on working with the files, I need a little help
> as to how to get the IP address out of the line of text into a variable
> for use.  Any help would appreciated.

Hi Tim

In the absence of sample data, I thought the output of Windows' ipconfig would
suffice. I hope the code below helps you do what you want. The regex just
searches for any sequence of four decimal numbers separated by dots and doesn't
check that the string is a valid IP address, but it is likely to suffice in most
cases.

Rob



use strict;
use warnings;

while (<DATA>) {
  if (/(\d+\.\d+\.\d+\.\d+)/) {
    print $1, "\n";
  }
}

__DATA__

PPP adapter Fast4:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 62.41.132.69
        Subnet Mask . . . . . . . . . . . : 255.255.255.255
        Default Gateway . . . . . . . . . : 62.41.132.69


OUTPUT

62.41.132.69
255.255.255.255
62.41.132.69


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to