Hi all,
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
This code worked well for ten years in all my PC and on all B4J and B4A projects.
Today while network is disconnected, B4J fails and returned the IP address of VirtualBox virtual network interface instead of the loopback interface (127.0.0.1).
At this point Copilot said me to disable on ControlPanel the VirtualBox network.
After I desabled it, B4J returned the Hyper-V IP address. Copilot at this point said that it depends on the networks priorities, to change the loopback priority to 1 and other virtuals to 5000 with Shell.
This do not changed before and after reboot. without network B4J always return the Hyper-V IP address.
I tried to completely disable Hyper-V and reboot, now B4J return an IPv6 address.
I tried to completely reset my network settings and reboot again, but nothing changed, It always return other IP address than loopback.
I always used all this things without any problem, all always worked, but now it fail.
The only way I found to get my real IP address or "127.0.0.1" is to use Inline Java or JavaObject to iterate all network interfaces, put here some filters to filter some IP addresses that way:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
I want to know if this is a problem on my PC or if other users have similar results, or may
depends of latest B4J releases, or may depends from automatic Windows updates.
The fact is that now it fails and I never installed any other programs to change this, I just updated to B4J 10.30 and
some days ago I had to reboot my PC because operating system updates required it.
Now I still develop a library that require network and I cannot proceed.
Many thanks
			
			
			
				B4X:
			
		
		
		Private Sock As ServerSocket
Log("IP: " & Sock.GetMyIP)
If Sock.GetMyIP = "127.0.0.1" Then
    LogError("This library need network connection. Please connect and try again")
    Return
End IfToday while network is disconnected, B4J fails and returned the IP address of VirtualBox virtual network interface instead of the loopback interface (127.0.0.1).
At this point Copilot said me to disable on ControlPanel the VirtualBox network.
After I desabled it, B4J returned the Hyper-V IP address. Copilot at this point said that it depends on the networks priorities, to change the loopback priority to 1 and other virtuals to 5000 with Shell.
This do not changed before and after reboot. without network B4J always return the Hyper-V IP address.
I tried to completely disable Hyper-V and reboot, now B4J return an IPv6 address.
I tried to completely reset my network settings and reboot again, but nothing changed, It always return other IP address than loopback.
I always used all this things without any problem, all always worked, but now it fail.
The only way I found to get my real IP address or "127.0.0.1" is to use Inline Java or JavaObject to iterate all network interfaces, put here some filters to filter some IP addresses that way:
			
				B4X:
			
		
		
		' Return IPv4 IP Adress (Wi‑Fi/Ethernet) if present.
' If not found return "127.0.0.1" that point to loopback.
Public Sub GetRealIPv4 As String
    Dim NI As JavaObject
    NI.InitializeStatic("java.net.NetworkInterface")
    Dim enNI As JavaObject = NI.RunMethod("getNetworkInterfaces", Null)
    If enNI.IsInitialized = False Then Return "127.0.0.1"
 
    Dim foundIP As String = ""
 
    Do While enNI.RunMethod("hasMoreElements", Null)
        Dim NI As JavaObject = enNI.RunMethod("nextElement", Null)
        If NI.RunMethod("isUp", Null) = False Then Continue
        If NI.RunMethod("isLoopback", Null) = True Then Continue
 
        Dim enAddr As JavaObject = NI.RunMethod("getInetAddresses", Null)
        Do While enAddr.RunMethod("hasMoreElements", Null)
            Dim ia As JavaObject = enAddr.RunMethod("nextElement", Null)
            Dim ip As String = ia.RunMethod("getHostAddress", Null)
            Log(ip)
            If ip.Contains(":") Then Continue ' IPv6
            If ip.StartsWith("127.") Then Continue ' loopback
            If ip.StartsWith("169.254.") Then Continue ' APIPA (VirtualBox)
            ' Exclude private range 172.16.x.x - 172.31.x.x (Hyper-V)
            If ip.StartsWith("172.") Then
                Dim parts() As String = Regex.Split("\.", ip)
                Dim secondOctet As Int = parts(1)
                If secondOctet >= 16 And secondOctet <= 31 Then Continue
            End If
            foundIP = ip
            Exit ' trovato un IPv4 valido
        Loop
 
        If foundIP <> "" Then Exit
    Loop
 
    If foundIP <> "" Then
        Return foundIP
    Else
        Return "127.0.0.1"
    End If
End SubI want to know if this is a problem on my PC or if other users have similar results, or may
depends of latest B4J releases, or may depends from automatic Windows updates.
The fact is that now it fails and I never installed any other programs to change this, I just updated to B4J 10.30 and
some days ago I had to reboot my PC because operating system updates required it.
Now I still develop a library that require network and I cannot proceed.
Many thanks
			
				Last edited: 
			
		
	
								
								
									
	
		
			
		
	
								
							
							 
				 
 
		 
 
		 
 
		 
 
		 )
) 
 
		 
 
		 
 
		 
 
		