B4J Question find IP PC

Isac

Active Member
Licensed User
Longtime User
I would like to retrieve the IP of my PC.

with java I imported this library:
B4X:
import java.net.*;

with java I am managed in this way:

B4X:
        Button btnNewButton = new Button(shell, SWT.NONE);
        btnNewButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
            try {
                InetAddress ip= InetAddress.getLocalHost();
                JOptionPane.showMessageDialog(null,ip.getHostAddress());
              
            } catch (UnknownHostException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }


how can I do with b4j?

thank you
 

Attachments

  • test.PNG
    test.PNG
    28.8 KB · Views: 254

jmon

Well-Known Member
Licensed User
Longtime User
You can do it several ways:

With jNetwork:
B4X:
Dim local As ServerSocket
local.Initialize(1, "")
Dim Host As String = local.GetMyIP

with jAWTRobot:
B4X:
Dim Host As String = AWT.SystemHostNameAndIPAddress

You can also parse a command line (ipConfig / ifConfig) result with jShell.
 
Upvote 0
Top