It is not necessary to explicitly embed the code into the page.  The
trade-off is having to use unsafeWindow. The following works for me.

var ip = unsafeWindow.java.net.Socket(document.location.host,
                                      document.location.port || 80)
                               .getLocalAddress().getHostAddress();
alert(ip);

I found that Socket must be passed the host and port of the window the
scripts runs on, otherwise the browser triggers a security exception.



On Tue, Sep 2, 2008 at 2:12 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hi Neng,
>
> On Tue, Sep 2, 2008 at 1:49 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> [cut]
>
> >> Now I found the solution of you problem is to add js into web page, sample
> >> as below:
> >> var body = document.body;
> >> var ip = document.createElement('script');
> >> ip.setAttribute('type','text/javascript');
> >> ip.innerHTML = 'var ip = new 
> >> java.net.InetAddress.getLocalHost();alert(ip);'
> >> body.insertBefore(ip,body.firstChild);
> >
> > I'm trying that now !
> > anyway java.net.InetAddress.getLocalHost() turns back the loopback
> > address (i.e. 127.0.0.1)
> > but what I need is the local address of my network interface (e.g.
> > 192.168.1.XX)... that's
> > why on my original code I use the trick that involve opening a socket
> > to a known hostname
> > (note that you need to grant permission to this kind of operation in
> > your java.policy )
>
> it works! I can confirm java.net.InetAddress.getLocalHost() gives back
> "loopback/127.0.0.1"
> whereas 
> java.net.Socket("www.opinioni.net",80).getLocalAddress().getHostAddress()
> returns what
> I need,  the IP address of my local network adapter

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to