B4J Question Get Wifi IP Addess of an rpi board

mike1967

Active Member
Licensed User
Longtime User
Hello, i have found and tryed this code in order to enumerate interface and get ipaddress :

B4X:
Sub Process_Globals
   Private servSocket As ServerSocket 
End Sub

Sub AppStart (Args() As String)
   servSocket.Initialize(0, "servSocket")
   Dim jo As JavaObject = Me
   jo.RunMethod("PrintAllInterfaces", Null)
   jo.RunMethod("InitServerSocket", Array(servSocket, "lo", 5000))
   servSocket.Listen
   
End Sub

#if JAVA
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Enumeration;
import anywheresoftware.b4a.objects.SocketWrapper.ServerSocketWrapper;
public static void PrintAllInterfaces() throws Exception {
      for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
    System.out.println(e.nextElement());
      }
   }
 
public static void InitServerSocket(ServerSocketWrapper ServerSocket, String interfaceName, int port) throws Exception {
     NetworkInterface ni = NetworkInterface.getByName(interfaceName);
    Enumeration e = ni.getInetAddresses();
    InetAddress ia = (InetAddress) e.nextElement();
     ServerSocket.ssocket = new ServerSocket(port, 0, ia);
}
#End If
Attachments

But its only show the interface name and not the ip address. Can someone suggest some library or code snippet in order to make this function ?
Thanks in advances
 
Top