commsinfrastructureapitest/commsinfrastructuresvs/suite/group/getipaddr.pl
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 #
       
     2 # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 #
       
    16 
       
    17 use Getopt::Long;
       
    18 
       
    19 sub Usage()
       
    20 	{
       
    21 print <<USAGE_EOF;
       
    22 Usage
       
    23 	getipaddr.pl -connection=Connection
       
    24 
       
    25 	Connection
       
    26 		Local Area Connection | RAS
       
    27 USAGE_EOF
       
    28 	}
       
    29 
       
    30 ###Validate parameters
       
    31 sub GetParameters()
       
    32 	{
       
    33 	my $connection="";
       
    34 
       
    35 	GetOptions(
       
    36 		'connection=s'	=> \$connection,
       
    37 		'help'			=> \$help);
       
    38 
       
    39 	if ( $help )
       
    40 		{
       
    41 	print	"Help\n";
       
    42 		Usage();
       
    43 		exit(0);
       
    44 		}
       
    45 
       
    46     return ($connection);
       
    47 	}
       
    48 
       
    49 sub GetIpAddr($)
       
    50 {
       
    51 	my ($connection) = @_;
       
    52 	$connection .= ":";
       
    53 
       
    54 	my	$sCfgFile = "./ipconfig.txt";
       
    55 	my	$sSrvAddr = "";
       
    56 	my	$cfgFound = 0;
       
    57 	system("ipconfig > $sCfgFile");
       
    58 	open(IPCONFIG, $sCfgFile);
       
    59 
       
    60 	foreach (<IPCONFIG>)
       
    61 	{
       
    62 		if (/.+adapter.+/)
       
    63 		{
       
    64 			if (/.+adapter\s+$connection/)
       
    65 			{
       
    66 				$cfgFound = 1;
       
    67 			}
       
    68 			else
       
    69 			{
       
    70 				$cfgFound = 0;
       
    71 			}
       
    72 		}
       
    73 		elsif($cfgFound == 1)
       
    74 		{
       
    75 			if(/IP.+\s+(\d+\.\d+\.\d+\.\d+)/)
       
    76 			{
       
    77 				$sSrvAddr = $1;
       
    78 			}
       
    79 		}
       
    80 	}
       
    81 	close (IPCONFIG);
       
    82 
       
    83 	return $sSrvAddr ;
       
    84 }
       
    85 
       
    86 sub Main()
       
    87 {
       
    88 	my	$connection="";
       
    89 	($connection)=GetParameters();
       
    90 
       
    91 	my	$ipaddr="";
       
    92 	$ipaddr=GetIpAddr($connection);
       
    93 
       
    94 	print "$ipaddr\r\n";
       
    95 }
       
    96 
       
    97 Main();