Hi,

i am capturing ip-address from windows machine and writing in a file in loop. in every iteration a one new ip-address will be assigned to windows that i have to append in the same file and check the ip-address already in the file they are also available in windows system(using ipconfig command).

for that i have written a script in perl. i am able to write the all ip-address but they are coming in this manner.

UEH4_ip = 11.0.0.1 UEH4_ip = 11.0.0.2 UEH4_ip = 11.0.0.3 UEH4_ip = 11.0.0.4
but it should be
UEH1_ip = 11.0.0.1 UEH2_ip = 11.0.0.2 UEH3_ip = 11.0.0.3 UEH4_ip = 11.0.0.4
and the script is
for (my $ii = 1; $ii <= 4; $ii++) { my @FileContents = `ipconfig`; my @UEinfo_fileContents = ReadFile($ue_file); my $FH = WriteFile($ue_file); my $lte_ip_address; foreach (@FileContents) { if ( $_ =~ /Address(.*):\s+([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} +\.[0-9]{1,3})/i ) { my $ip_address = $2; $ip_address =~ s/\s+//gi; if ($ip_address =~ m/^11\.\d+\.\d+\.\d+/) { $lte_ip_address = $ip_address; foreach (@UEinfo_fileContents) { if ($_ =~ m/UEH\d+(.*)=\s+([0-9]{1,3}\.[0-9]{1,3}\ +.[0-9]{1,3}\.[0-9]{1,3})/i) { my $file_ip = $2; if ($file_ip =~ m/^11\.\d+\.\d+\.\d+/) { my $abc = "UEH".$ii . "_ip"; if ($ip_address =~ m/$file_ip/) { print $FH "$abc" . " = $lte_ip_address +\n"; last; } else{ print $FH "$abc" . " = $lte_ip_address +\n"; last; } } } } } } } undef @UEinfo_fileContents; @UEinfo_fileContents = ReadFile($ue_file); foreach (@UEinfo_fileContents) { if ($_ =~ m/UEH\d+(.*)=\s+([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\ +.[0-9]{1,3})/i) { my $file_ip = $2; if ($file_ip =~ m/^11\.\d+\.\d+\.\d+/) { my $temp = 0; foreach (@FileContents) { if ( $_ =~ /Address(.*):\s+([0-9]{1,3}\.[0-9]{1,3} +\.[0-9]{1,3}\.[0-9]{1,3})/i ) { my $IP_address = $2; $IP_address =~ s/\s+//gi; if ($IP_address =~ m/^11\.\d+\.\d+\.\d+/) { if ($file_ip =~ m/$IP_address/) { $temp = 1; last; } } } } if ($temp == 0){ print "$file_ip : Disconnect\n"; } } } } }
please suggest me the way.. thanks in adavnce

In reply to IP-Stored in file not working by Rahul Gupta

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.