How to get the host’s IP address from within VuGen

Sometimes an application running on a client (even a web broswer) will send the IP address of the client machine to the server at the Application layer, rather than the Network layer. This is surprisingly common with web-based apps designed to run on a company’s intranet.

To make a BPM script accurately mimic a real user, the script should also send back the real IP address of the machine it is running from.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Action()
{
	char * vuserIpStr;
 
	web_set_sockets_option("IP_ADDRESS_BY_INDEX",  "1"); // Note that this forces the BPM to use the first NIC. This may cause confusion if the BPM has multiple NICs.
	vuserIpStr = (char *) lr_get_vuser_ip(); // If the IP was set with the web_set_sockets_option function using the IP_ADDRESS_BY_INDEX option, lr_get_vuser_ip returns that IP. 
 
	if ( (vuserIpStr == NULL) || (strcmp(vuserIpStr,"") == 0) ) {
		lr_error_message("!!ERROR!!::Cannot get IP address for Virtual User.");
		lr_abort();
	} else {
		lr_output_message("NOTE::My Vuser IP address = [%s]", vuserIpStr);
	}
 
	return 0;
}

 


Related posts:

  1. Persistent Data in VuGen with MySQL One of the main drawbacks with VuGen is the inability...
  2. Parameterising Unix/Posix timestamps in VuGen A common question from people creating web-based VuGen scripts is...
  3. Harvesting file names with VuGen VuGen isn’t just a tool for load testing and application...
  4. VuGen Code Snippets This is a repository of code snippets. Please send me...
  5. Changing LoadRunner/VuGen log options at runtime LoadRunner has a whole bunch of logging options. These can...


Bookmark using any bookmark manager!

 

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “How to get the host’s IP address from within VuGen”

  1. An alternative would be to use the following code:

    Action()
    {
    	int rc;
    	char *peer;
    
    	rc = lrs_create_socket("socket1", "TCP", "LocalHost=:8888", LrsLastArg); 
    
    	peer = lrs_get_socket_attrib("socket1", LOCAL_ADDRESS );
    
    	lr_output_message("ip is %s", peer);
    
    	return 0;
    }
    
  2. I have vague memories of playing with the Windows GetIpAddrTable() function, which can be found in Iphlpapi.dll.

    Cheers,
    Stu.

Leave a Reply