I'm a newbie to JMeter currently, I'm testing a Rest API, I need to record the server IP from which the response is coming.
I'm able to test the API but not able to record the IP address. How can I achieve the same?
I'm a newbie to JMeter currently, I'm testing a Rest API, I need to record the server IP from which the response is coming.
I'm able to test the API but not able to record the IP address. How can I achieve the same?
Assuming you send to server name in variable serverName
, so add JSR223 PostProcessor (or other JSR223 element) and get the IP using InetAddress:
This class represents an Internet Protocol (IP) address.
InetAddress address = InetAddress.getByName(vars.get("serverName"));
log.info address.getHostAddress();
vars.put("serverIP", address.getHostAddress());
You can then use ${serverIP}
variable
Put the following code into "Script" area:
log.info('Source IP address: ' + InetAddress.getByName(sampler.getDomain()).getHostAddress())
It will print the IP address to jmeter.log file
If you want to save this IP for later re-use you can amend the code like:
vars.put('ip', InetAddress.getByName(sampler.getDomain()).getHostAddress())
and add the next line to user.properties file:
sample_variables=ip
As a result you will have an extra column in .jtl file containing IP address of the server.
More information: