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