How to get the ip Address of the System
Comments
-
Hi kamit2733,
you can start with simple script:
from com.parasoft.api import * import socket def my_ip(): s = socket.gethostbyname(socket.gethostname()) Application.showMessage("My IP: " + str(s))
Ireneusz Szmigiel
1 -
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-java1 -
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
0 -
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')),0 -
I have tried the above code getting the abive error can some help me out how to fix this.
0 -
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.
0 -
I hav installed jython 2.7 now will that work.
0 -
I hav installed jython 2.7 now will that work.
No, that will not work. I hope my previous comment makes sense to you.
0 -
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.
0 -
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
0 -
try this one...find ip address
0