B4J Question Wrong IP Address returned by ServerSocket GetMyIP

max123

Well-Known Member
Licensed User
Longtime User
Hi all,
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 If
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:
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 Sub

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
 
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
This works for me (getmyip seems to be using cached data after ethernet disconnected)
B4X:
    Try
        Dim jo As JavaObject
        jo.InitializeStatic("java.net.InetAddress")
        Dim addr As JavaObject = jo.RunMethod("getByName", Array("8.8.8.8"))
        Dim reachable As Boolean = addr.RunMethod("isReachable", Array(1000)) ' timeout in ms
        If reachable Then
            Log("OK") ' has internet
        Else
            Log("FAIL") ' no internet
        End If
    Catch
        Log("FAIL (exception)") ' no internet
    End Try

And I have Hyper-V and VirtualBox installed with no problems.
Thanks @Daestrum I will try it...
I already tried something similar, but using isUp instead of isReachable, but didn't worked as expected.

All the code can solve the problem but not the full problem to know because Socket.GetMyIP when offline do not return to me a software loopback.

EDIT: Tried it, your code works very well, and it is small, anyway can get if device is connected and if not connected there are no error logs, just the log you put in the code. :eek: But another time, this is not the full solution to my problem that depends of some network configuration inside the operating system.

Now that I remember, in past I already used isReachable directly on pure java side (on Eclipse) to get the network connection.
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
This works for me (getmyip seems to be using cached data after ethernet disconnected)
B4X:
    Try
        Dim jo As JavaObject
        jo.InitializeStatic("java.net.InetAddress")
        Dim addr As JavaObject = jo.RunMethod("getByName", Array("8.8.8.8"))
        Dim reachable As Boolean = addr.RunMethod("isReachable", Array(1000)) ' timeout in ms
        If reachable Then
            Log("OK") ' has internet
        Else
            Log("FAIL") ' no internet
        End If
    Catch
        Log("FAIL (exception)") ' no internet
    End Try

And I have Hyper-V and VirtualBox installed with no problems.
So @Daestrum if you used this, Socket.GetMyIP don't works for you if you have VBox and Hyper-V active ?
This is really important to know....
My setup with all these always worked without do nothing of special and Socket.GetMyIP always worked here.
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Well at this point... i wanna say me experience.. ofcouse not sure if this is the right place... but...

B4X:
...
    wait for (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
        Return j.GetString
    Else
        Try
            If j.GetString.Length>0 Then
                'Return j.ErrorMessage
                Return j.ErrorMessage'& " - Unknown Error"
            End If
        Catch
            Log(LastException)
        End Try
    End If
..

If use ELSE and then have Try Catch End Try....
and haven't a success... it may return me the previous (the right one - 10min before) cached - j.GetString

This ofcourse can be my error - or something wrong i ve did... but I am curious for the right solution... to get back error messages..
@Magma I do requests to Google Translator, if request fails Google send an html page with the error etc... I do it that way....
I don't kow if it is useful for you...
B4X:
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(sURL)
    ' Evita 403 su alcuni dispositivi/proxy:
    j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0")
   
    Wait For (j) JobDone(j As HttpJob)

    If j.Success Then
        Dim Data() As Byte = Bit.InputStreamToBytes(j.GetInputStream)
        StartDecode(Data, TextToSpeak)
    Else
        Dim err As String = j.ErrorMessage
        If err.StartsWith("<!DOCTYPE html") Or err.StartsWith("<html") Then
'            Log(">>>>>>>>>>>>>>>>>>>>> TROVATO HTML NEL RAMO ELSE <<<<<<<<<<<<<<<<<<<<<<<")
            mReport.Success = False
            mReport.Text = TextToSpeak
            mReport.Error = "Google TTS returned an HTML page (possible temporary block)"
            RaiseCompleteEvent
            Sleep(2000)
        Else
            mReport.Success = False
            mReport.Text = TextToSpeak
            mReport.Error = err
            RaiseCompleteEvent
        End If
    End If
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
With the help of AI:

To connect Hyper-V and VirtualBox virtual machines to a network on a Windows PC, configure the network adapters for each VM to use either Bridged or External connection types so they appear on the same network (LAN) as your physical machine, enabling direct communication and internet access if desired.

Hyper-V Networking​

  • Virtual Switch Creation: Use Hyper-V Manager to create a virtual switch; choose External if you want the VMs to connect to your LAN and access the internet. This binds the switch to a physical network adapter on your PC.
    • Go to Hyper-V Manager → Virtual Switch Manager → New virtual switch → Select "External", choose your host adapter, and apply.
  • VM Adapter Attachment: In each VM’s settings, attach the network adapter to the newly created external switch. This ensures VMs get IP addresses from the same DHCP server as physical devices.
  • Verification: Launch the VM, log in, and use ipconfig (Windows) or ip a (Linux) inside the guest to verify it has an IP in the LAN subnet.

VirtualBox Networking​

  • Bridged Adapter Setup: In VirtualBox Manager, for each VM, open Settings → Network, then set "Attached to:" as Bridged Adapter. Select your host’s physical NIC in the drop-down menu. This places the VM on your LAN.
  • Start and Verify: Boot your VM and check its network IP configuration (ipconfig or ip a). It should obtain an IP address from your LAN DHCP server matching your physical network’s scheme.

Host-Only/Internal Options: For isolated VM networks (communication only between VMs and host, not LAN), use Host-Only or Internal Network settings.

Tips and Troubleshooting​

  • Ensure your Windows Firewall allows local communication (if you need access between host and VMs).
  • If the VM isn’t acquiring a LAN IP, double-check adapter selection and virtual switch settings.
  • Both platforms support multiple virtual NICs per VM for advanced scenarios.

PlatformNetwork TypeLAN AccessInternet AccessIsolation
Hyper-VExternalYesYesNo
Hyper-VInternalHost & VMsNoYes
VirtualBoxBridgedYesYesNo
VirtualBoxHost-OnlyHost & VMsNoYes

This enables direct network and internet connectivity for VMs, making RDP and SMB, as well as guest-to-guest and guest-to-host networking straightforward.

--- End of AI ----

Back to my network expertise. So ask your self first what is Purpose and look in the table to find the Means = what kind of Network Type you need to use from the previous table. Then install step by step and test if you have successful network connectivity = do I get a response as expected before taking the next installation step.
So if you only need access from your local WiFi network (as I understand) then you need LAN Access. A B4X application is connected to the Wi-Fi LAN. So if you open a DOSbox you need to get a response from the network interface you just have configured. The successful test to the same address should also be working from your B4X test program. You can also use the tracert command to follow the session in your network. Start first at the local Hyper-V and VirtualBox virtual machine(s) and then repeat the test on another machine connected to the same (Wi-Fi) network where the Hyper-V and VirtualBox virtual machine(s) are connected to type the correctness of firewall rules.
Furthermore, don't forget that the lookback address 127.0.0.1 is living before the Windows firewall so that standard it cannot be reached from another device connected to the network living at the public site of the Windows firewall.
Documented how you make your setup included the tests and where in the network you did your test for a handy reference in the future when you have network connectivity problems. Include use network addresses with use subnet mask so you can detect with an IP calculator for overlapping subnet addresses (believe me, sometimes even professionals makes mistakes with this. This gives very strange results, or no connectivity problems). To keep your network simple with little chance for mistake: use a subnet mask of 255.255.255.0. This gives you the opportunity to put 253 devices in each VLAN.
Hopes this will help you.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks @MicroDrie it is a bit complicated to me. This worked from the begin without do nothing in the system,
I just created virtual switches for Hyper-V, but just to have connection on some virtual machines.
The fact now is that it does not works even if I uninstall all. Some configuration may is corrupted.
Reset network settings from Windows settings had no results.

If some peoples want some prompt or shell commands results to know what happen, I will post here. Example Copilot suggested me some commands to use in shell to get/set metrics of all network interfaces, but I don't rebember now.... it tell me even how to temporaly disable Hyper-V and then reenable it back using shell.
But because I'm no pratical, I only tried to change some metrics and change the loopback to high priority and virtual networks to lower priorities.

What I doing is completely the opposite of this, I'm going to it and removed all external switch, to know if this is the problem that B4J dont see my IP:
  • Virtual Switch Creation: Use Hyper-V Manager to create a virtual switch; choose Externalif you want the VMs to connect to your LAN and access the internet. This binds the switch to a physical network adapter on your PC.
    • Go to Hyper-V Manager → Virtual Switch Manager → New virtual switch → Select "External", choose your host adapter, and apply.
  • VM Adapter Attachment: In each VM’s settings, attach the network adapter to the newly created external switch. This ensures VMs get IP addresses from the same DHCP server as physical devices.
  • Verification: Launch the VM, log in, and use ipconfig (Windows) or ip a (Linux) inside the guest to verify it has an IP in the LAN subnet.
Furthermore, don't forget that the lookback address 127.0.0.1 is living before the Windows firewall so that standard it cannot be reached from another device connected to the network living at the public site of the Windows firewall.
But I only use it local on the same machine, not remotely

My subnet mask already is 255.255.255.0
1756304936665.png
 
Last edited:
Upvote 0

Magma

Expert
Licensed User
Longtime User
@Magma I do requests to Google Translator, if request fails Google send an html page with the error etc... I do it that way....
I don't kow if it is useful for you...
B4X:
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(sURL)
    ' Evita 403 su alcuni dispositivi/proxy:
    j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0")
  
    Wait For (j) JobDone(j As HttpJob)

    If j.Success Then
        Dim Data() As Byte = Bit.InputStreamToBytes(j.GetInputStream)
        StartDecode(Data, TextToSpeak)
    Else
        Dim err As String = j.ErrorMessage
        If err.StartsWith("<!DOCTYPE html") Or err.StartsWith("<html") Then
'            Log(">>>>>>>>>>>>>>>>>>>>> TROVATO HTML NEL RAMO ELSE <<<<<<<<<<<<<<<<<<<<<<<")
            mReport.Success = False
            mReport.Text = TextToSpeak
            mReport.Error = "Google TTS returned an HTML page (possible temporary block)"
            RaiseCompleteEvent
            Sleep(2000)
        Else
            mReport.Success = False
            mReport.Text = TextToSpeak
            mReport.Error = err
            RaiseCompleteEvent
        End If
    End If

Seems nice ... but If for some reason not having internet at all... returns something? or app stops working at all ?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
to @aeric and @teddybear yes I already done this, but the ptoblem is that make an http request while there are network, it will work successfully, if there is no network, the log show the error that seem I cannot avoid. Because I have to use this for a library I don't like it, instead I wanted to log only my error.
I really don't like to make things complicated.
I just need to wrap the Try-Catch correctly to catch the error.
I can just read the error message returned and decide what is next.
e.g "Unable to resolve host" which is very likely indicate that my device is having no internet.

B4X:
Sub TestConnection As ResumableSub
    Dim Success As Boolean
    Try
        Dim job As HttpJob
        job.Initialize("", Me)
        job.Download("https://mydomain.com/connect.php")
        Wait For (job) JobDone(job As HttpJob)
        If job.Success Then
            Log(job.GetString)
            Success = True
        Else
            ShowConnectionError(job.ErrorMessage)
        End If
    Catch
        Helper.ShowToastMessage("Connection failed.", False)
    End Try
    job.Release
    Return Success
End Sub

Sub ShowConnectionError (strConnError As String)
    If strConnError.Contains("Unable to resolve host") Then
        Helper.ShowToastMessage("Connection failed.", True)
    Else If strConnError.Contains("timeout") Then
        Helper.ShowToastMessage("Connection timeout.", True)
    Else
        Helper.ShowToastMessage("Error: " & strConnError, True)
    End If
End Sub

This is taken from my old project. I don't use this anymore.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
I'm not sure at at 100%, but this don't worked for me, the try catch cannot know if the request failed, only HttpJob can do it.
If you want be sure I will try another time that and I confirm you. If this works for you, probably is my mistake.

The first problem with your code is that I cannot use it in the library Initialize method, because it cannot be ResumableSub.
The @Daestrum code works here successfully.
1756293845625.png

Here is how I adapted the @Daestrum code:
B4X:
    If DeviceIsOnline Then
        Log("TTS: Device connected. IP Address: " & mSock.GetMyIP)
        If SubExists(mCallback, mEventName & "_Ready") Then CallSub2(mCallback, mEventName & "_Ready", True)
    Else
        Log("TTS library need network connection. Connect and try again.")
        If SubExists(mCallback, mEventName & "_Ready") Then CallSub2(mCallback, mEventName & "_Ready", False)
    End If
    .............
    .............
    Sub DeviceIsOnline As Boolean
    Try
        Dim jo As JavaObject
        jo.InitializeStatic("java.net.InetAddress")
        Dim addr As JavaObject = jo.RunMethod("getByName", Array("8.8.8.8"))
        Dim reachable As Boolean = addr.RunMethod("isReachable", Array(1000)) ' timeout in ms
        If reachable Then
'            Log("OK") ' has internet
            Return True
        Else
'            Log("FAIL") ' no internet
            Return False
        End If
    Catch
'        Log("FAIL (exception)") ' no internet
        Return False
    End Try
End Sub
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
@aeric just to be sure I've done a chek on your code:
B4X:
    Wait For (DeviceIsOnline) Complete (isOnline As Boolean)
    If Not(isOnline) Then
        Log("Device in not online")
        Return
    End If
 
    . . . . .
 
    Sub DeviceIsOnline As ResumableSub
    Dim Success As Boolean = False
    Try
        Dim job As HttpJob
        job.Initialize("", Me)
        job.Download("https://mydomain.com/connect.php")
        Wait For (job) JobDone(job As HttpJob)
        If job.Success Then
'            Log(job.GetString)
            Log("aeric code: Connection Success")
            Success = True
        Else
'            ShowConnectionError(job.ErrorMessage)
            Log("aeric code: Connection Failed: " & job.ErrorMessage)
            Success = False
        End If
    Catch
        Log("aeric code: Connection Failed.")
        Success = False
    End Try
    job.Release
    Return Success
End Sub
The log show aeric code: Connection Success if the device is online, it even show aeric code: Connection Failed: java.net.UnknownHostException: Host sconosciuto (mydomain.com) if offline, but even show the request error on the log, so the try/catch three do nothing here in any case, even if request fail.
You can try yourself.

Here the log:
TTS: Speaking in [en] [32] Characters -> [Text to speech with Basic 4 Java]
Set language [en]
java.net.UnknownHostException: Host sconosciuto (mydomain.com)
at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:52)
at java.base/java.net.InetAddress$PlatformResolver.lookupByName(InetAddress.java:1059)
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1673)
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:1003)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1663)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1528)
at okhttp3.Dns$Companion$DnsSystem.lookup(Dns.kt:49)
at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.kt:164)
at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.kt:129)
at okhttp3.internal.connection.RouteSelector.next(RouteSelector.kt:71)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:205)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.executeWithTimeout(OkHttpClientWrapper.java:175)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.access$0(OkHttpClientWrapper.java:172)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$ExecuteHelper.run(OkHttpClientWrapper.java:220)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1589)
ResponseError. Reason: java.net.UnknownHostException: Host sconosciuto (mydomain.com), Response:
aeric code: Connection Failed: java.net.UnknownHostException: Host sconosciuto (mydomain.com)
Device in not online
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Tiny version for you (harder to read but less lines)
B4X:
Sub deviceIsOnline As Boolean
    Try
        Return (Null).As(JavaObject).InitializeStatic("java.net.InetAddress").RunMethodJO("getByName", Array("8.8.8.8")).RunMethod("isReachable", Array(1000)) ' timeout in ms
    Catch
        Return False
    End Try
End Sub

No rules broken here lol
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
@aeric just to be sure I've done a chek on your code:
B4X:
    Wait For (DeviceIsOnline) Complete (isOnline As Boolean)
    If Not(isOnline) Then
        Log("Device in not online")
        Return
    End If
 
    . . . . .
 
    Sub DeviceIsOnline As ResumableSub
    Dim Success As Boolean = False
    Try
        Dim job As HttpJob
        job.Initialize("", Me)
        job.Download("https://mydomain.com/connect.php")
        Wait For (job) JobDone(job As HttpJob)
        If job.Success Then
'            Log(job.GetString)
            Log("aeric code: Connection Success")
            Success = True
        Else
'            ShowConnectionError(job.ErrorMessage)
            Log("aeric code: Connection Failed: " & job.ErrorMessage)
            Success = False
        End If
    Catch
        Log("aeric code: Connection Failed.")
        Success = False
    End Try
    job.Release
    Return Success
End Sub
The log show aeric code: Connection Success if the device is online, it even show aeric code: Connection Failed: java.net.UnknownHostException: Host sconosciuto (mydomain.com) if offline, but even show the request error on the log, so the try/catch three do nothing here in any case, even if request fail.
You can try yourself.

Here the log:
You mean Try Catch failed to catch the error?
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
You mean Try Catch failed to catch the error?
Yes, only the job success is called here, True or False, not the catch exception part.
Try yourself, comment just the Try and Catch part, your results will not change regards the request success, it is handled by j.Success.
But ask to @Erel to be sure. May the Try/Catch can serve here for other errors than http request return error status.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
So, someone know another way to reset the networks on windows instead to do it from the settings ?
I completely uninstalled VirtualBox, but now Socket.GetMyIP return the Hyper-V IP address when device is offline.
But return the right IP address when online.
The software Loopback exists on the system, but probably have low priority and B4J don't see it, instead see other IP of other interfaces, the first one it find with highter priority.
 
Last edited:
Upvote 0

Magma

Expert
Licensed User
Longtime User
Hmm network reset...at cmd as admin

netsh winsock reset

And...

ipconfig /flushdns

And then

Reboot pc...

But... I don't know if that will change metric ...
Did you setup any services.msc to have gateway your pc ?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
the try/catch three do nothing here in any case
Yes, try-catch doesn't help much but the else case for job.Success when it is false is sufficient to tell there is an error in the connection.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Thanks @MicroDrie it is a bit complicated to me. This worked from the begin without do nothing in the system,
I just created virtual switches for Hyper-V, but just to have connection on some virtual machines.
The fact now is that it does not works even if I uninstall all. Some configuration may is corrupted.
Reset network settings from Windows settings had no results.
Yes, it worked, yes, you haven't changed anything, so there's a good chance that one or more program updates over a longer period of time have made small changes that led to the crash.
Forget how it worked. Look at the steps described in post 24 and check at each step whether you have a connection from a VM to the Fritz.box router. Use tracert to follow the route and check whether it meets your expectations and needs, as shown in the table in post 24. Only proceed to the next step if the previous one is completely correct. The only simple question is, how far have you gotten?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
So @Daestrum if you used this, Socket.GetMyIP don't works for you if you have VBox and Hyper-V active ?
This is really important to know....
My setup with all these always worked without do nothing of special and Socket.GetMyIP always worked here.
As I said getmyip didn't detect the ethernet being disconnected - it kept reporting the IP that was valid when it was connected.
Thats why I used a real access to the internet - that detected the ethernet out in under a second.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Hmm network reset...at cmd as admin

netsh winsock reset

And...

ipconfig /flushdns

And then

Reboot pc...

But... I don't know if that will change metric ...
Did you setup any services.msc to have gateway your pc ?
Thanks, I will try it at this point....
Did you setup any services.msc to have gateway your pc ?
I don't know exactly what you mean, but I only used services.msc to activate/deactivate some services like Bonjour and others.

Yes, try-catch doesn't help much but the else case for job.Success when it is false is sufficient to tell there is an error in the connection.
Yes it is the same that I said, the try/catch do not influence here, but j.Success return False, to know no network, the only thing here is that it show the error request on the log, and I don't like it on a library as already explained, this was the addon of try/catch to catxh the error without log out.

Yes, it worked, yes, you haven't changed anything, so there's a good chance that one or more program updates over a longer period of time have made small changes that led to the crash.
Forget how it worked. Look at the steps described in post 24 and check at each step whether you have a connection from a VM to the Fritz.box router. Use tracert to follow the route and check whether it meets your expectations and needs, as shown in the table in post 24. Only proceed to the next step if the previous one is completely correct. The only simple question is, how far have you gotten?
I completely removed VirtualBox, and have no VM now, I only want to fix this IP mistake, so I think that less is involved, the simpler it sholuld be.

The only simple question is, how far have you gotten?
I don't know what you mean here, now I'm in a point that GetMyIP see my real IP if online, but see my Hyper-V IP (instead of sw loopback) when offline.
After it not worked I removed manually duplicated instances for VBox and Hyper-V, something with same names but with index #2 from Control Panel, uninstalled, probably this can be a mistake, but another time I done this only after GetMyIP returned a wrong IP when offline.

To @Daestrum many thanks for infos, I remeber now. Now the official code in my library is your last DeviceIsOnline. If it works in a PC with IP problems like mine, I think it always works and better that Socket.GerMyIP.
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
This will be a long post, and it is become clear that many things are unclear to you and that we don't know exactly what you want. Based on 40 years of experience and the fact that you live between aqueducts, I will try to explain the problem to you in simple terms. Simply put, we're stuck on the observation that the water doesn't reach its final destination via various aqueducts. At various points along the way, it repeatedly turns out there's no water. All this without knowing the water's intended route. And that's precisely the problem when you don't clarify what you want to achieve. Depending on your specific needs, some things along the way are possible, and others aren't.
Without this knowledge, requesting a network response adds nothing to a solution. Randomly testing networks without knowing whether the response is intended or unintended will not help you solve connectivity problems in your network.
Create a sketch of the network, draw a cloud for Hyper-V, your VirtualBox network, and your Wi-Fi network. Include the IP range, subnet mask, and default gateway for each network. Also specify whether the hosts should be able to communicate with each other and where (with which IP address) your B4X program should communicate with which hosts. If necessary, number the host as host1, host2, and so on. Based on that sketch and the terminology from the table in post 24, we can help you with the necessary configuration and provide testing it with the associated network tests.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
@MicroDrie I probably didn't explain myself well from the beginning of this thread.

I just want to return to the original state, just to get my IP (Wi-Fi or Ethernet) if I'm connected, and 127.0.0.1 (software loopback) if I'm not connected, while using Socket.GetMyIP. So I don't need anything special to do special things.

When I activated Hyper-V a while ago, I didn't move anything; Windows just created a virtual network.
The same thing happened when I installed VBox; it created another virtual network. I've never moved anything there.

This has worked for 3 years without problems.

Now, even though I've completely uninstalled VBox, when I don't have a network, Socket.GetMyIP still gives me the Hyper-V IP address. If I disable it completely, it doesn't give me 127.0.0.1.

Because I'm not expert here, the only command prompt I know is ipconfig, that I posted. If you know others commands to know what happen, I can post here the output.
 
Last edited:
Upvote 0
Top