OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Beanshell: Getting IP-address

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
Teme
General User
General User


Joined: 03 May 2006
Posts: 8
Location: Finland

PostPosted: Wed May 10, 2006 5:21 pm    Post subject: Beanshell: Getting IP-address Reply with quote

This code snippet prints:"My ip-address is: xxx.xxx.xxx.xxx" to current write document. It is bean shell.

Code:

import com.sun.star.uno.UnoRuntime;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XText;
import com.sun.star.text.XTextRange;
import java.net.InetAddress;

oDoc = XSCRIPTCONTEXT.getDocument();
xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
xText = xTextDoc.getText();
xTextRange = xText.getEnd();

InetAddress address = InetAddress.getLocalHost();
xTextRange.setString( "My address is:"+address.getHostAddress() +"\n");

return 0;


Teme
Back to top
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Thu May 11, 2006 7:42 am    Post subject: Reply with quote

Thank you for this code.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Thu May 11, 2006 12:36 pm    Post subject: Reply with quote

Very nice !!

This is the BASIC wrapper around Teme's function:

Install the following into Beanshell/MyMacros/Tools/getIP.bsh
Code:
import java.net.InetAddress;
InetAddress address = InetAddress.getLocalHost();
return address.getHostAddress();


This is how to call it from Basic:
Code:
const PATH_TO_GETIP = "vnd.sun.star.script:Tools.getIP.bsh?language=BeanShell&location=user"

sub TestDownloadUrlToFile
msgbox getIP()
end sub


function getIP() as String
oMSPF = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory") 
oScript=oMSPF.createScriptProvider("").getScript(PATH_TO_GETIP)

getIP = oScript.invoke(Array(), Array(), Array())
end function
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group