How to get the player's internal IP address?

How can I get a player’s internal, local IPV4 address in-game? (Like 192.168.xx.xx). My project is going to be released on Android, so I cannot use the command prompt or other Windows-specific things.
Any help would be greatly appreciated!

If I’m correct the data to receive the IPV4 address can be found in UNetConnection. There is an instance of this class within APlayerController.
The RemoteAddressToString function of UNetConnection should return the information you are looking for.

https://docs.unrealengine.com/en-US/…ion/index.html

I don’t have a project in which I’m able to test it currently, can you verify if it is what you are looking for?

I’m quite new to C++ in ue4, so if possible, I’d really appreciate it if you could walk me though the steps to make it work!

Also what if we want the LOCAL IP address, not the public one? Does it work for that?

This is a bit unwise, as it can be nullptr if you are playing just locally or are the server.
see: [APlayerController | Unreal Engine 5.2 Documentation

Ok so for anyone having this issue, you can use this plugin, which will allow you to get the IPV4 address locally via UPNP. I haven’t tested it, but it may point you in the right direction - https://www.unrealengine.com/marketp…on-for-release

Another option would be to use the Socket subsystem. Add the “Sockets” module to your build.cs. Then:


#include "SocketSubsystem.h"

...

bool bCanBindAll;
TSharedPtr<class FInternetAddr> Addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, bCanBindAll);
FString MyIP = Addr->ToString(false); 

4 Likes

Plugin Simple UDP TCP Socket Client

Thank you for your post,
it helped me

Cool. Navigating this engine isn’t exactly easy, so I’m glad this info was of use to someone.

1 Like

Yeah your correct,
your code work for android & Pc, Can you help me for getting ios ip address,
i’m new to c++
Thanks

How do I select the network adapter that it gets the IP? I have Wifi in use and (Ethernet and VirtualAdapter ) that are disabled, the game is picking up the IP of a random adapter that is not in use.

Thank you, In 2023 it’s still work!

In the documentation of the method said that we can use function GetLocalAdapterAddresses to get array of addresses and choose which you want to use:
image