B4J Question How to obtain WAN IP (Public IP) of the Websocket Wep app user

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

As described in the subject is there a way to get the WAN IP (External/Public) IP of the users of a Websocket based web application ?

The ABMMaterial App will be hosted on a VPS, I would like to log the Public IP of the users accessing my ABMaterial app.

I am aware about few websites, when visited will display list your Public IP. The same can be used via HttpUtils to read the external IP. I would like to know is there any way other than that via WebSocket technology.

Any help will be appreciated
 

Daestrum

Expert
Licensed User
Longtime User
Not sure if
B4X:
webSocket.UpgradeRequest.RemoteAddress

returns what you want.
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Yes. I tried that, but it is returning my Local IP ie my LAN IP and not the WAN IP
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Yes. I tried that, but it is returning my Local IP ie my LAN IP and not the WAN IP
Do you have a proxy in between you and the WAN? If so, the proxy will be the RemoteAddress. You would have to look at the headers of the HTTP request to see what the actual remote address is. The problem with that is that proxies don't really have a standard on how/what headers they set to indicate what the original address was that made the request.
 
Upvote 0

mindful

Active Member
Licensed User
Yes. I tried that, but it is returning my Local IP ie my LAN IP and not the WAN IP
You get your lan ip when the server app is running on your vps on which your connect to it via it's public ip? Because there is no way the vps server can know your lan ip ...

Or do you get your lan ip while you run the server app in debug or release on local pc ?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Just read this part of your post again.
The ABMMaterial App will be hosted on a VPS, I would like to log the Public IP of the users accessing my ABMaterial app.
So i assume you are running it on a local machine as @mindful said.

Until you run it on the server or set up port forwarding on your router it will return your lan address.
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Friends,

Today, I am away from my work PC. Shall test it by tomorrow.

I already have the ABM app running on a VPS server. Yesterday, I modified the application's code to include webSocket.UpgradeRequest.RemoteAddress
, that could read the public IP of the app user. I was testing the possibilities of capturing the WAN IP of the user on my development PC ie a local PC, though I was connected to the internet while testing.

May be as pointed by @mindful and @Daestrum , I should upload it to the VPS server to see the public IP of the user. I assumed that, as I am already connected to the Internet, running the app on a local development PC would also return the my public IP. May be I guessed it wrong. I too feel that, from the VPS, I may get the expected result.

Tomorrow, I shall upload the modified app on to the VPS server and then test it to find out whether the app could identify the users WAN IP.

Shall publish the result here.

Thank you all for pointing out the possible cause.
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

I uploaded the app to my VPS and as per my tests webSocket.UpgradeRequest.RemoteAddress is returning the External/Public IP of the app user. So this is working as expected. Sorry for creating the confusions.

Thank you all.
 
Upvote 0
Top