EGL Development User Group

Expand all | Collapse all

get ip address from client

  • 1.  get ip address from client

    Posted Wed April 29, 2009 12:10 AM

    is there a way to get an ip address of a client using the richui applications? I need it as a parm for a wsdl call.

    nick_tn


  • 2.  Re: get ip address from client

    Posted Mon May 03, 2010 09:42 AM
    Hello Nick,

    Your post has the status 'Answered'.
    Can you share the solution with us?

    Thanks in advance,
    Ortwin
    Ortwin


  • 3.  Re: get ip address from client

    Posted Tue May 04, 2010 05:00 PM
    I thought that the combination of server-side includes (in Tomcat) and an EGL external type written in JavaScript would do the trick but I didn't have much (okay, any) success.

    What worked for me was to enable server-side includes in Apache and then invoke a web page ("getIP.shtml") as a REST service call to get the client's IP address.

    To enable SSI on the Apache side, I added this to my Apache server's "httpd.conf" file:
    Options IncludesNoExec
    AddType text/html .shtml
    AddHandler server-parsed .shtml

    Here is "getIP.shtml" (it uses SSI to get the IP address of the client). This file is in the directory from which my Apache server serves up content:
    <!--#echo var="REMOTE_ADDR"-->

    Here is the EGL interface to my service ("IPAddress.egl"):
    interface IPAddress
    function getIP() returns (string)
    {@GetRest { uriTemplate="http://www.mycompany.com/getIP.shtml", responseFormat = NONE }};
    end

    And here is a RUI Handler to test it ("Test.egl"):
    import com.ibm.egl.rui.widgets.*;

    handler Test type RUIhandler {initialUI = ui }

    ui Box{ columns = 1, width = "400", height= "400", children = b1, l1 };
    b1 Button{ text="Who Am I?", onClick ::= onClick_b1 };
    l1 TextLabel { text="-------------------------------" };


    function onClick_b1(e Event in)
    iPAddress IPAddress {@RestBinding};

    call iPAddress.getIP() returning to getIP;
    end

    function getIP(retResult string in)
    l1.text = retResult;
    end

    end

    When you click on the "Who Am I?" button the service is invoked to get the client's IP address.
    http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/download/11864-3253/ip.jpeg

    Hope this helps.
    --Dan
    Attachments:
    ip.jpeg
    dan_darnell


  • 4.  Re: get ip address from client

    Posted Tue May 04, 2010 08:02 PM
    Hi Dan,

    very nice solution. any chance you could add a project interchange with your needed projects to the samples gallery?
    SystemAdmin


  • 5.  Re: get ip address from client

    Posted Fri May 21, 2010 11:26 AM
    Following up:
    The solution I posted earlier only works in the IDE ... not when deployed to a server. Once deployed, the service call comes from the server, not the client. Therefore, the IP address that is resolved is the IP address of the server. Not very useful (smacks forehead)!

    There is another way to skin this cat. With the same scripted HTML setup described in my earlier post, use the following external type in your Rich UI client.

    com.mycompany.custom.widgets.BrowserFunctions.egl
    externalType BrowserFunctions extends Widget type JavaScriptObject {
    relativePath = "com/mycompany/custom/widgets",
    javaScriptName = "BrowserFunctions" }

    function getIP() returns(string);
    end


    com/mycompany/custom/widgets/BrowserFunctions.js
    egl.defineClass(
    'com.mycompany.custom.widgets', 'BrowserFunctions',
    {
    "constructor" : function()
    {

    },

    "getIP" : function () {
    xhttp=new XMLHttpRequest();
    xhttp.open("GET","http://www.mycompany.com/getIP.shtml",false);
    xhttp.send("");
    x=xhttp.responseText;
    return x;
    }
    });

    Then, in your Rich UI code:
    import com.ibm.egl.rui.widgets.*;
    import com.mycompany.custom.widgets.BrowserFunctions;

    handler Test type RUIhandler {initialUI = ui }

    ui Box{ columns = 1, width = "400", height= "400", children = b1, l1 };
    b1 Button{ text="Who Am I?", onClick ::= onClick_b1 };
    l1 TextLabel { text="-------------------------------" };

    function onClick_b1(e Event in)
    browserFunctions BrowserFunctions {};
    l1.text = browserFunctions.getIP();
    end

    end


    With this approach the invocation of the scripted HTML page comes from the client side and the address returned is that of the client.

    --Dan
    dan_darnell


  • 6.  Re: get ip address from client

    Posted Fri February 13, 2015 06:35 AM

    Hi Dan,

    I tried your Solution, but i get an error in this line:

    xhttp.open("GET","http://192.168.10.3/getIP.shtml",false);

    [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://localhost:5590/frommclient/handlers_loga/test.html?contextKey=8 :: .getIP :: line 19217" data: no]

     

    This is my httpd.conf:

     

      1    LoadModule mod_ibm_si /QSYS.LIB/QHTTPSVR.LIB/QZISI.SRVPGM
      2    LoadModule deflate_module /QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM
      3    WebSpherePluginConfig /QIBM/UserData/WebSphere/AppServer/V85/Express/profiles/WAS855_2/config/cells/POWER7_WAS855_2/nodes/POWER7_WAS855_2/servers/IHS_WEBSE855_2/plugin-cfg.xml
      4    LoadModule was_ap20_module /QSYS.LIB/QWAS85A.LIB/QSVTAP22LF.SRVPGM
      5    # HTTP server (powered by Apache) configuration
      6    DocumentRoot /www/webse855_2/htdocs
      7    ServerRoot /www/webse855_2
      8    Options -ExecCGI -FollowSymLinks -SymLinksIfOwnerMatch -Includes -IncludesNoExec -Indexes -MultiViews
      9    Listen *:80 http
      10    ThreadsPerChild 220
      11    SetOutputFilter DEFLATE
      12    AccessFileName .htaccess
      13    TraceEnable On
      14    LogFormat "%h %T %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
      15    LogFormat "%{Cookie}n \"%r\" %t" cookie
      16    LogFormat "%{User-agent}i" agent
      17    LogFormat "%{Referer}i -> %U" referer
      18    LogFormat "%h %l %u %t \"%r\" %>s %b" common
      19    CustomLog logs/access_log combined
      20    SetEnvIf "User-Agent" "Mozilla/2" nokeepalive
      21    SetEnvIf User-Agent ^Mozilla/5.0 !no-gzip
      22    SetEnvIf User-Agent MSI[E].(5\.5|6\.0); !no-gzip
      23    SetEnvIf User-Agent ^. no-gzip
      24    SetEnvIf "User-Agent" "JDK/1\.0" force-response-1.0
      25    SetEnvIf "User-Agent" "Java/1\.0" force-response-1.0
      26    SetEnvIf "User-Agent" "RealPlayer 4\.0" force-response-1.0
      27    SetEnvIf "User-Agent" "MSIE 4\.0b2;" nokeepalive
      28    SetEnvIf "User-Agent" "MSIE 4\.0b2;" force-response-1.0
      29    SetEnvIfNoCase Request_URI \.(js|css)$ gzip-only-text/html=0
      30    WASInstance /QIBM/UserData/WebSphere/AppServer/V85/Express/profiles/WAS855_2 5733W85 1
      31    AppServer *ALL Start End
      32    
      33    AddType text/html .shtml
      34    AddHandler server-parsed .shtml
      35    AddOutputFilter INCLUDES .shtml
      36    SetEnv gzip-only-text/html 1
      37    Header Always Append Vary User-Agent env=!dont-vary
      38    DirectoryIndex index.html
      39    
      40    
      41    
      42    <Directory />
      43         Order Deny,Allow
      44         Deny From all
      45    </Directory>
      46    <Directory /www/webse855_2/htdocs>
      47         Order Allow,Deny
      48         Allow From all
      49    </Directory>
      50    Alias /Lohn /Lohn
      51    <Directory /Lohn>
      52        Order allow,deny
      53        Allow from all
      54    </Directory>

    Do you have a Solution for my problem?

    Thanks in advance!

    Marcel-D


  • 7.  Re: get ip address from client

    Posted Fri February 13, 2015 08:27 AM

    If you search for the error code you displayed 0x80004005 , then you will get numerous hits on the internet. Some of them seem to mention that it is an access denied problem. I don't know if you are running this under windows or not, but take a look at the search results. 

    Jeff.Douglas


  • 8.  Re: get ip address from client

    Posted Fri February 13, 2015 08:50 AM

    Hi Jeff,

    i searched for the code, but i didn't find something usefull.

    It's running on Webshpere Application Server 8.5.5 on a Power 7 with IBM I.

     

    I also tried to run my EGL Programm in Google Chrome with following exception:

    • Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://192.168.10.3/getIP.shtml'. at Error (native) at egl.defineClass.getIP (test.html?contextKey=5:20393:11) at egl.defineRUIHandler.get_ip (test.html?contextKey=5:24734:31) at egl.defineRUIHandler.start (test.html?contextKey=5:24698:9) at new egl.defineRUIHandler.constructor (test.html?contextKey=5:24668:9) at clazz [as eze$$thisClass] (test.html?contextKey=5:941:27) at Function.egl.startupInit (test.html?contextKey=5:25295:22) at test.html?contextKey=5:25317:5

    Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://192.168.10.3/getIP.shtml'.
    [CRRUI2095E] Die EGL-Funktionsaufrufe, die zu diesem Fehler führen, konnten nicht gefunden werden.


    Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://192.168.10.3/getIP.shtml'.
    frommclient/handlers_loga/test.html?contextKey=5:25313
    [CRRUI2095E] Die EGL-Funktionsaufrufe, die zu diesem Fehler führen, konnten nicht gefunden werden.
    Marcel-D


  • 9.  Re: get ip address from client

    Posted Fri February 13, 2015 09:09 AM

    After reading this information from the post, and I could be wrong, but it looks like Dan's implementation for the 2nd part is relying on the installation of the getIP.shtml from the first part. I think you need to do both of tasks that Dan pointed out, because it looks like the 2nd part is trying to do a get on the installed shtml file.

    Jeff.Douglas


  • 10.  Re: get ip address from client

    Posted Fri February 13, 2015 09:18 AM

    Hi Jeff,

    I did both tasks Dan pointed out.

    I installed the shtml file and then i did the 2nd task....

     

     

    I tried to call the shtml wit a FireFox Rest Client addons and i  think it looks fine.

    But the Response Body is not the IP ?!?!

    Marcel-D


  • 11.  Re: get ip address from client

    Posted Fri February 13, 2015 01:07 PM

    In your Apache config you are not allowing server-side includes. You have

    Options -IncludesNoExec   
    ...but you need...Options IncludesNoExec   

    Make this change and restart Apache. Then you should see the IP address when you invoke getIP.shtml from a browser.

     

    That said ... this isn't the reason that the Rich UI is failing.

    The most likely reason that the Rich UI is failing is because of a cross-domain request. This happens when your Rich UI is trying to make a request to a server other than the one it originated from. The browser says "nope, can't let you do that."

    I wrote another post on this:

    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014633228&ps=25

    When Tomcat was involved, the best and most reliable way to get the client IP and avoid security issues with cross-site scripting was through Tomcat-enabled server-side includes.

    You are using WebSphere though, I believe. You might be alright based on the relationship between the HTTP server and the application server ... you'll just have to try it.

    Dan

     

     

     

     

     

    dan_darnell


  • 12.  Re: get ip address from client

    Posted Mon February 16, 2015 04:47 AM

    Hi Dan,

    i tried your solution with the JSP page and it's working!

    Thank you very much!!!

    Marcel-D


  • 13.  RE: Re: get ip address from client

    Posted Wed September 08, 2021 08:30 AM
    Dan

    Is the mentioned article down? I cannot access this URL.
    Tks

    I wrote another post on this:

    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014633228&ps=25



    ------------------------------
    Osvaldo Jose de Oliveira Menezes
    Analista
    RellegusTI
    Orlândia
    +55 16 3818-0203
    ------------------------------