I am working on a Service where i need to provide my ipAddress in the returnURL.
Can some one let me know which method to use in Jython to fetch the IP Address of my system such that when i run the test it automatically fetches the IP.
Please be aware that a system may have multiple NICs and each NIC may have multiple IP addresses assigned to it. Depending on your requirements, you may need to check all of those and pick the IP address you think you want to use. The script from the previous post is for python (Jython). In contrast, there are java APIs for collecting IP addresses which you could call from a Groovy script. In particular, there is java.net.NetworkInterface.getNetworkInterfaces() which returns the list of network interfaces. For each network interface, you can call java.net.NetworkInterface.getInetAddresses() to get the list of IP address for that network interface.
As @benken_parasoft mentioned you may need to get different IP address based on NIC.
There are a plenty of examples on the web for using python to get IP of current machine:
There's either an error in your script or possibly your Jython home is not pointing to a Jython 2.5.2 installation, having an incompatible socket.py. See docs for details about configuring Jython home. You can't configure Jython home to some other python installation or a different version of Jython (must be Jython 2.5.2).
However, if you require a timely resolution then I'd recommend you consider contacting Parasoft support to help look at this with you.
Happy to help. Ideally SOAtest would use the current Jython release (2.7 as of right now). I posted a little detail about this at changing-python-version-in-parasoft-soatest
Comments
Hi kamit2733,
you can start with simple script:
Ireneusz Szmigiel
Please be aware that a system may have multiple NICs and each NIC may have multiple IP addresses assigned to it. Depending on your requirements, you may need to check all of those and pick the IP address you think you want to use. The script from the previous post is for python (Jython). In contrast, there are java APIs for collecting IP addresses which you could call from a Groovy script. In particular, there is java.net.NetworkInterface.getNetworkInterfaces() which returns the list of network interfaces. For each network interface, you can call java.net.NetworkInterface.getInetAddresses() to get the list of IP address for that network interface.
There are plenty of examples on the web for using the Java APIs I mention. For example:
https://stackoverflow.com/questions/494465/how-to-enumerate-ip-addresses-of-all-enabled-nic-cards-from-java
As @benken_parasoft mentioned you may need to get different IP address based on NIC.
There are a plenty of examples on the web for using python to get IP of current machine:
https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib
I am gettin the following error
Traceback (most recent call last) :, File "" , line 7 , in , SyntaxError ("mismatch input ', ' expecting NAME", ('pyclasspath/socket.py', 208, 50, ' def makefile(self, mode='r' , buffering=None, *, \n')),
I have tried the above code getting the abive error can some help me out how to fix this.
There's either an error in your script or possibly your Jython home is not pointing to a Jython 2.5.2 installation, having an incompatible socket.py. See docs for details about configuring Jython home. You can't configure Jython home to some other python installation or a different version of Jython (must be Jython 2.5.2).
However, if you require a timely resolution then I'd recommend you consider contacting Parasoft support to help look at this with you.
I hav installed jython 2.7 now will that work.
No, that will not work. I hope my previous comment makes sense to you.
Hi @benken_parasoft got it sorted out . there was a issue with the Jython home and the path. got it fixed. Thanks buddy
for all the help.
Happy to help. Ideally SOAtest would use the current Jython release (2.7 as of right now). I posted a little detail about this at changing-python-version-in-parasoft-soatest
try this one...find ip address