Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private Label1 As Label
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
MainForm.Show
Dim jo As JavaObject=Me
Dim rightipfromwlan As String
Log ("CORRECT IP from wlan0 is :" & jo.RunMethod("getIp", Array("wlan0")))
rightipfromwlan=jo.RunMethod("getIp", Array("wlan0"))
Dim server1 As ServerSocket
Dim myip As String
server1.Initialize(5505, "server1")
myip= server1.GetMyIP
Log ("B4J get this IP:" & myip)
If myip=rightipfromwlan Then
Log ("PERFECT - I have IP from WLAN - program will continue")
Else
Log ("WRONG - program get IP from ETHERNET and not from WIFI adapter")
End If
End Sub
#if JAVA
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Enumeration;
public static void PrintAllInterfaces() throws Exception {
for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
BA.Log("" + e.nextElement());
}
}
#End If
#if JAVA
import java.net.InetAddress;
import java.net.Inet6Address;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Enumeration;
public static String getIp(String interfaceName) throws Exception {
for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
NetworkInterface ni = e.nextElement();
if (ni.getName().equals(interfaceName)) {
Enumeration<InetAddress> en2 = ni.getInetAddresses();
while (en2.hasMoreElements()) {
InetAddress ia = en2.nextElement();
if (!ia.isLoopbackAddress()) {
if ((ia instanceof Inet6Address) == false) {
return ia.getHostAddress();
}
}
}
}
}
return "";
}
#End If
#if JAVA
import java.io.*;
import java.net.*;
import java.util.*;
import static java.lang.System.out;
public static void listIF() throws SocketException {
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets))
displayInterfaceInformation(netint);
}
static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
BA.Log("Display name: "+netint.getDisplayName());
BA.Log("Name: "+netint.getName());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
BA.Log("InetAddress: "+ inetAddress);
}
}
#End If