Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    8
    Rep Power
    0

    Default How to get client ip address from Web Service hosted on OAS 10.1.2

    Hi,

    Can anyone advice how to get the remote client IP from a web service (java) hosted on Oracle Application Server 10.1.2.

    The below code works if the web service is hosted on Tomcat.
    MessageContext msgCtxt = MessageContext.getCurrentMessageContext();
    String IP = (String)msgCtxt.getProperty("REMOTE_ADDR");

    This code is causes built errors on the OAS 10.1.2 since it needs Axis and many other Jars. I tried to insert the jars needed but unfortunately when i was able to compile it returned a java.lang.NullPointerException.

    Is there a way to get the IP address of the client that calls this web service ?
    Or is there a way to read the SOAP request maybe i can retrieve the client IP from it.

    Thanks for your support,
    regards

  2. #2
    Join Date
    Feb 2011
    Location
    Ahmedabad
    Posts
    36
    Rep Power
    0

    Default Re: How to get client ip address from Web Service hosted on OAS 10.1.2

    [Sample Code]
    ===========
    [WebMethod]
    Java Code:
    public string GetCustomerIP()
    {
    string CustomerIP = "";
    if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
    {
              CustomerIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
    }
    else
    {
               CustomerIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
     }
                return CustomerIP;
    }
    In above sample code, HTTP_VIA is used to judge whether the client is using proxy server. If client uses proxy server, then the web method will try to obtain IP address behind the proxy server. In many situations, the IP addresses we get are probably the addresses of proxy server. Below is the information on HTTP proxy:

    1. Not Use Any Proxy Server:

    REMOTE_ADDR = IP address of client
    HTTP_VIA = No value or No display
    HTTP_X_FORWARDED_FOR = No value or No display

    2. Use Transparent Proxies:

    REMOTE_ADDR = IP address of proxy server
    HTTP_VIA = IP address of proxy server
    HTTP_X_FORWARDED_FOR = Real IP address of client

    3. Use Normal Anonymous Proxies:

    REMOTE_ADDR = IP address of proxy server
    HTTP_VIA = IP address of proxy server
    HTTP_X_FORWARDED_FOR = IP address of proxy server

    4. Use Distorting Proxies:

    REMOTE_ADDR = IP address of proxy server
    HTTP_VIA = IP address of proxy server
    HTTP_X_FORWARDED_FOR = Random IP address

    5. Use High Anonymity Proxies (Elite proxies):

    REMOTE_ADDR = IP address of proxy server
    HTTP_VIA = No value or No display
    HTTP_X_FORWARDED_FOR = No value or No display


    Another fact that may affect the result of above web service is the configuration of router. If the router of local area network enables NAT (network address translation), then the IP address obtained is the address used by the router to access external network. If NAT is disabled, then the IP address is the client's IP address within local area network.

    Before use above sample code, we should first consider the real product environment and then use it accordingly.

    Reference
    ========
    A Probability to Get Wrong Information
    KBSoft IP Locator - CodeProject

    Getting the Real IP Of Your Users
    Getting The Real IP Of Your Users
    Last edited by hemant_metalia; 10-06-2011 at 04:07 PM.
    Hemant Metalia
    cool

  3. #3
    Join Date
    Apr 2010
    Posts
    8
    Rep Power
    0

    Default Re: How to get client ip address from Web Service hosted on OAS 10.1.2

    Thanks for your quick reply.

    I tried the above code in my environment but unfortunately it didn't work because Oracle Application Server 10.1.2 works on java 1.4 :(
    I added the http.jar file but unfortunately the following code "HttpContext.Current.Request.ServerVariables["HTTP_VIA"] " is in error and i'm not able to compile.

    Is there any way I can get it to work. Are there any jar file i should use ?

    Thanks
    Lana

Similar Threads

  1. Replies: 0
    Last Post: 03-18-2010, 06:39 PM
  2. Getting client IP address
    By shinjan in forum JavaServer Pages (JSP) and JSTL
    Replies: 6
    Last Post: 12-20-2009, 01:36 AM
  3. Client IP Address
    By goodjonx in forum Networking
    Replies: 3
    Last Post: 09-23-2009, 11:27 AM
  4. Web service client
    By Tshegofatsom in forum New To Java
    Replies: 1
    Last Post: 09-09-2009, 03:31 PM
  5. How to get IP Address of the client
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-05-2008, 11:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •