I am trying to write a script in beanshell for jmeter through which I can get the IP address of a machine (using ipconfig
command and extract only IP Address from the output)?
The following code is giving only the IP of the request of which needs to be passed to jmeter.
String IP = InetAddress.getByName(prev.getURL().getHost()).getHostAddress();
vars.put("IP", IP);
Can anyone guide me?
Try this one:
vars.put("IP", org.apache.jmeter.util.JMeterUtils.getLocalHostIP());
Demo:
You can also use __machineIP() function in the "Parameters" section and refer the value as Parameters
or bsh.args[0]
in the script body
References:
you can also use as follows:
log.info("IP " + InetAddress.getLocalHost().getHostAddress());
String IP = InetAddress.getLocalHost().getHostAddress();
vars.put("localIP", IP);
later, you can refer the IP using the following syntax:
${localIP} or vars.get("localIP")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With