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; } |
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.
September 13th, 2009 at 1:20 pm
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; }September 13th, 2009 at 4:26 pm
I have vague memories of playing with the Windows GetIpAddrTable() function, which can be found in Iphlpapi.dll.
Cheers,
Stu.
January 8th, 2011 at 8:07 pm
Is it possible to make a vuser to pick up a different IP for each iteration ? doing so can make a real unique client/user each iteration for the app..