# Obtain local ip address

**URL:** <https://forums.unrealengine.com/t/obtain-local-ip-address/336258>\
**Category:** C++\
**Tags:** Networking, sockets, unreal-engine, CPP, question\
**Created:** [October 23, 2015, 5:00pm UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258 "2015-10-23T17:00:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_d090acc21](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d090acc21](https://forums.unrealengine.com/u/anonymous_user_d090acc21)\
**Post date:** [October 23, 2015, 5:00pm UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/1 "2015-10-23T17:00:18Z")

</div>

Hi Guys,

I have a problem obtaining my local ipaddress.  
Maybe someone could help, it should be quite straight forward :S.

These lines should give me the ip:

```
TSharedRef<FInternetAddr> LocalAddr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalBindAddr(*GLog);

FString myLocalIp = LocalAddr->ToString(0);

```

But i always obtain a ipaddress of 0.0.0.0 in the string.  
The same problem i have with the RecvFrom function wich contains a pointer to the remote address.  
It also returns 0’s all the time ☹

Any help would be appreciated.  
Thanks in advance.

Cheers.

B

---

<div class="post-metadata">

**Author:** ![krazzei](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@krazzei](https://forums.unrealengine.com/u/krazzei)\
**Post date:** [December 21, 2015, 9:09pm UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/2 "2015-12-21T21:09:08Z")

</div>

Hi,

I’m using GetLocalHostAddr for the local IP (the IP that is used to communicate with your router).

here is some sample code:

```
bool canBind = false;
TSharedRef<FInternetAddr> localIp = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, canBind);

if (localIp->IsValid())
{
    GLog->Log(localIp->ToString(false)); // if you want to append the port (true) or not (false).
}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0f59718a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0f59718a](https://forums.unrealengine.com/u/anonymous_user_0f59718a)\
**Post date:** [October 11, 2016, 9:47am UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/3 "2016-10-11T09:47:40Z")

</div>

Hi!  
How do I set up the includes for this to work with a “launcher” version of Unreal Engine? I get compilation errors with just #include “SocketSubsystem.h”, so I guess I need to setup dependency modules, but I don’t understand how.

---

<div class="post-metadata">

**Author:** ![krazzei](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@krazzei](https://forums.unrealengine.com/u/krazzei)\
**Post date:** [October 11, 2016, 5:14pm UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/4 "2016-10-11T17:14:09Z")

</div>

It’s been a while since I’ve done this and our networking has changed since then so this might be incorrect… But I think the header file is just “Networking.h” that is a header that includes a bunch of networking headers (sockets, subsystems, ipv4/6, etc). Then in your project’s Build.cs you will need to add the “Networking” module to your “PublicDependencyModuleNames” list.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_04f32a061](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_04f32a061](https://forums.unrealengine.com/u/anonymous_user_04f32a061)\
**Post date:** [September 5, 2018, 7:35pm UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/5 "2018-09-05T19:35:50Z")

</div>

This worked for me:

```
#include <SocketSubsystem.h>
#include <IPAddress.h>

bool canBind = false;
TSharedRef<FInternetAddr> localIp = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, canBind);
return (localIp->IsValid() ? localIp->ToString(false) : "");

```

And in file `ProjectName.Build.cs`:

```
PublicDependencyModuleNames.AddRange(new string[] { /*Some more stuff*/ "Sockets" });

```

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [April 28, 2020, 5:47am UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/6 "2020-04-28T05:47:37Z")

</div>

Works like a charm, thanks! You should upgrade this to an Answer — except I should point out that this always obtains 127.0.0.1 if you run it on Android, which isn’t useful. But it works great on Windows.

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [April 28, 2020, 4:23pm UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/7 "2020-04-28T16:23:52Z")

</div>

Thank you! Works great on Windows. Just a warning for others if you’re developing for Android. It has some weird issue that makes it return 127.0.0.1 no matter what, though. I hope they fix it in the near future. I think it’s related to Issue UE-62267

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [August 15, 2020, 3:42am UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/8 "2020-08-15T03:42:29Z")

</div>

I really need this to work in Android on WiFi ☹

---

<div class="post-metadata">

**Author:** ![Aros\_Prince](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aros\_Prince](https://forums.unrealengine.com/u/Aros_Prince)\
**Post date:** [February 4, 2021, 9:50am UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/9 "2021-02-04T09:50:33Z")

</div>

What about iOS? Does it work there?

---

<div class="post-metadata">

**Author:** ![gabor.papp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gabor.papp](https://forums.unrealengine.com/u/gabor.papp)\
**Post date:** [July 26, 2021, 7:59pm UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/10 "2021-07-26T19:59:00Z")

</div>

Thank you. Seems to be working now on Android too.

---

<div class="post-metadata">

**Author:** ![Taqi3075](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Taqi3075](https://forums.unrealengine.com/u/Taqi3075)\
**Post date:** [January 30, 2023, 9:44am UTC](https://forums.unrealengine.com/t/obtain-local-ip-address/336258/11 "2023-01-30T09:44:28Z")

</div>

For those still stuck  
0.0.0.0 isn’t working for some reason

the following have worked for me

```auto
	FIPv4Address Addr;
	FIPv4Address::Parse(localIp->ToString(false), Addr);

```
