IP Address Lookup returning IPv6 instead of IPv4 Address

Minty

AWF VIP
Local time
Today, 14:00
Joined
Jul 26, 2013
Messages
10,681
This is happening to a number of users but not all, which makes fixing it rather troublesome.

I use the code below to return an IPv4 External IP address, so that we can automatically update an Azure SQL firewall, via some clever HTTP encryption.
It's loosely based on a number of similar codes on the interwebs.
Code:
Function GetMyPublicIP() As String

    Dim HttpRequest As Object

    On Error Resume Next
    'Create the XMLHttpRequest object.
    Set HttpRequest = CreateObject("MSXML2.XMLHTTP")

    'Check if the object was created.
    If Err.Number <> 0 Then
        'Return error message.
        GetMyPublicIP = "Could not create the XMLHttpRequest object!"
        'Release the object and exit.
        Set HttpRequest = Nothing
        Exit Function
    End If
    On Error GoTo 0

    'Create the request - no special parameters required.
    'HttpRequest.Open "GET", "http://myip.dnsomatic.com", False - ''  This site rejects me after a few uses.
    HttpRequest.Open "GET", "https://myexternalip.com/raw", False
    'Send the request to the site.
    HttpRequest.sEnd

    'Return the result of the request (the IP string).
    GetMyPublicIP = HttpRequest.responseText

End Function

The problem as stated above is that it is returning an IPv6 address, on some end users' machines. It works fine for my colleagues and other people in the same organisation. But not all of them.

I'm at a bit of a loss, we have checked and there is no common thread, majority are Windows 10 some are Win 11, some have been connected to a VPN some never connect to a VPN.

If they go to any of the websites directly via a browser, they always get the correct IPv4 address.
Confused.com
 
@Minty,
Are you saying happens to just some users that are all on the same WAN ip address?
I have IPV6 set on my wireless connection (normally I do not, so obviously forgot this one) and that code shows my WAN address, but ,my router has no option for IPV6.
 
Well, I clicked on the first source that looked vaguely interesting:
404 - Error page not available.

When I add the line
HttpRequest.setRequestHeader "User-Agent", "Mozilla/5.0"
I get an unspecified error.
I checked they have either Edge or Chrome as their default browsers.

With all the best will in the world, after 20 + years of playing with Access, I'd like to think I understood Access Error handling enough to know what the effects of the line are.

Two users have never used a VPN and are suffering from the issue. I tried it through a VPN from home (I'm on a fixed IP, so have a VPN available to check things like this work) and still got the correct results.

I have also wondered if it is the MSXML2 provider request, however, that works on my Win 11 machine and a Win 10 machine I have here.

@Gasman - no they are separate home networks, no VPN, I suspect different providers, although which provider they are with might be worth checking.

So far that makes the score Mr ChatGPT 0 - Rest of the World 0

But RotW has made an interesting suggestion about checking the providers...
 
Well, I clicked on the first source that looked vaguely interesting:
404 - Error page not available.

When I add the line
HttpRequest.setRequestHeader "User-Agent", "Mozilla/5.0"
I get an unspecified error.
I checked they have either Edge or Chrome as their default browsers.

With all the best will in the world, after 20 + years of playing with Access, I'd like to think I understood Access Error handling enough to know what the effects of the line are.

Two users have never used a VPN and are suffering from the issue. I tried it through a VPN from home (I'm on a fixed IP, so have a VPN available to check things like this work) and still got the correct results.

I have also wondered if it is the MSXML2 provider request, however, that works on my Win 11 machine and a Win 10 machine I have here.

@Gasman - no they are separate home networks, no VPN, I suspect different providers, although which provider they are with might be worth checking.

So far that makes the score Mr ChatGPT 0 - Rest of the World 0

But RotW has made an interesting suggestion about checking the providers...
Well I am on Virgin, but suspect if the router cannot hold an IPV6 address, then IPV4 would be all you get?
 
But by definition, you would be far more likely to get an IPv4 ( which is what I need), than the IPv6 address.
Has anyone actually tested the original code to see what they get, rather than relying on the useless ramblings of the AI?

It's very difficult to investigate when I can't make it go wrong.
 
The problem as stated above is that it is returning an IPv6 address, on some end users' machines. It works fine for my colleagues and other people in the same organisation. But not all of them.

IF you have a router, you are internally using Network Address Translation, and NAT substitutes local DHCP-assigned addresses for socket targets. You might not have a public IPv4 address if the connection in question is based on an IPv6 connection. Not all IPv6 addresses translate down.
 
Has anyone actually tested the original code to see what they get,
Hi. I just tried the code you posted and got an IPv4 address, which I compared against what I got when I browsed to https://whatismyipaddress.com and they matched. However, the website also said my IPv6 is "Not detected." So, I'm not sure if that helps or not. Cheers!
 
What happens if you enter nslookup host using powershell or cmd in those machines?
Depending on the network configuration, you'll either get the computers' IP private address on the local network, or no IP at all.
Only if the computers are connected directly to the internet, which is rather unlikely for a client workstation, you will get an IP address usable to configure a remote firewall.
 
Depending on the network configuration, you'll either get the computers' IP private address on the local network, or no IP at all.
Only if the computers are connected directly to the internet, which is rather unlikely for a client workstation, you will get an IP address usable to configure a remote firewall.
I just checked, it's not the public IP of my computers, just something similar. Maybe the IP of the device providing connectivity to my home router, given that it returns the same in different computers here.

I guess OP just has to find a more reliable provider for his IPs, the http request seems alright, although I don't know why he wants to check if the http request object was created, but the more checks in place, the better, sometimes.
 
Maybe the IP of the device providing connectivity to my home router, given that it returns the same in different computers here.

From that description, it is probably the ISP's IP address for the server currently servicing your account. Which might be related to the ISP's physical wiring scheme.

For instance, I know that a LOT of people in my neighborhood will have similar addresses because the AT&T connection box is across the street from my house. I watched them lay the fiber cable for that box and watched them when they ran fiber from there to my house (replacing the thin-copper connections.)
 
Sorry been away!

It's the WAN IP address that's required, and what is returned 99.9% of the time by sites like What's My IP.
We use it for home workers, and I suspect it's stopped working due to a configuration change rolled out by a corporate IT.

It has been working for about 2 years, and has suddenly started giving strange results.
 
Sorry been away!

It's the WAN IP address that's required, and what is returned 99.9% of the time by sites like What's My IP.
We use it for home workers, and I suspect it's stopped working due to a configuration change rolled out by a corporate IT.

It has been working for about 2 years, and has suddenly started giving strange results.
Well the router my part time bosses have just aquired appears to have an IPv6 option?
 
Well the router my part time bosses have just aquired appears to have an IPv6 option?
I have a IPv6 capable router, but Virgin don't support it so my home internet will always be over IPv4, except when I use a VPN that can connect using IPv6 (though my connection to the VPN will be over IPv4)
 

Users who are viewing this thread

Back
Top Bottom