How to get the ip Address of the System

kamit2733kamit2733 Posts: 16

Hi ,

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.



  • Ireneusz SzmigielIreneusz Szmigiel Posts: 219 ✭✭✭

    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

  • benken_parasoftbenken_parasoft Posts: 1,009 ✭✭✭

    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 which returns the list of network interfaces. For each network interface, you can call 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:

  • Ireneusz SzmigielIreneusz Szmigiel Posts: 219 ✭✭✭
    edited November 2017

    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:

  • kamit2733kamit2733 Posts: 16

    I am gettin the following error
    Traceback (most recent call last) :, File "" , line 7 , in , SyntaxError ("mismatch input ', ' expecting NAME", ('pyclasspath/', 208, 50, ' def makefile(self, mode='r' , buffering=None, *, \n')),

  • kamit2733kamit2733 Posts: 16

    I have tried the above code getting the abive error can some help me out how to fix this.

  • benken_parasoftbenken_parasoft Posts: 1,009 ✭✭✭

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

  • kamit2733kamit2733 Posts: 16

    I hav installed jython 2.7 now will that work.

  • benken_parasoftbenken_parasoft Posts: 1,009 ✭✭✭

    I hav installed jython 2.7 now will that work.

    No, that will not work. I hope my previous comment makes sense to you.

  • kamit2733kamit2733 Posts: 16

    Hi @benken_parasoft got it sorted out . there was a issue with the Jython home and the path. got it fixed. Thanks buddy :smile: for all the help.

  • benken_parasoftbenken_parasoft Posts: 1,009 ✭✭✭

    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

  • johnkimberjohnkimber Posts: 1

    try this one...find ip address

Sign In or Register to comment.