| View previous topic :: View next topic |
| Author |
Message |
Teme General User


Joined: 03 May 2006 Posts: 8 Location: Finland
|
Posted: Wed May 10, 2006 5:21 pm Post subject: Beanshell: Getting IP-address |
|
|
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 |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Thu May 11, 2006 12:36 pm Post subject: |
|
|
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 |
|
 |
|