2

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?

Farhana Naaz Ansari
  • 7,524
  • 26
  • 65
  • 105

2 Answers2

0

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

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0
  1. Add JSR223 PostProcessor as a child of the HTTP Request sampler
  2. 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

    JMeter Get Source IP address

  3. 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:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • hi, I'm getting following exception : ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor javax.script.ScriptException: javax.script.ScriptException: java.net.UnknownHostException – Sameer Malhotra Feb 27 '18 at 11:34
  • Thank you very much for support it helps alot.It's getting blocked. – Sameer Malhotra Feb 27 '18 at 12:06