UE C++获取本机IP地址
开发环境
UE 5.2.1
Visual Studio 2019 16.11.19
代码部分
XXX.Build.cs文件添加以下依赖:
PrivateDependencyModuleNames.AddRange(new String[]{"Sockets"})
.cpp文件:
#include "SockerSubsystem.h"
void GetIp() {
bool bBind = false;
TSharedRef<FInternetAddr> LocalAddr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, bBind);
FString LocalIp = "0.0.0.0";
if (LocalAddr->IsValid()) {
LocalIp = LocalAddr->ToString(false);
}
UE_LOG(LogTemp, Warning, TEXT("LOCAL_IP: %s"), *LocalIp);
}
结果
注:Andriod平台可能获取失败
标签:LocalAddr,获取,C++,LocalIp,IP地址,UE From: https://www.cnblogs.com/YeeBy/p/18293417