如何将IP地址的整数值转换为标准IP地址

How to convert integer value of ip address to standard IP address

请问。你能帮我如何将 ip 地址的整数值转换为标准 ip 地址吗?

A 从

中得到整数值
tmpWifiServiceNative:= TAndroidHelper.Activity.getSystemService(TJContext.JavaClass.WIFI_SERVICE);

tmpWifiManager:= TJWifiManager.Wrap((tmpWifiServiceNative as ILocalObject).GetObjectID);

tmpWifiIPAddress:= tmpWifiManager.getDhcpInfo.ipAddress //This returns integer value

只需使用这个功能:

uses
  Androidapi.Helpers,
  Androidapi.JNIBridge,
  Androidapi.JNI.Java.Net,
  Androidapi.JNI.JavaTypes;
  

function ConvertIntegerIPAddressToString(AIntegerIPAddress: Integer): string;
var
  IPAddress: Integer;
  SystemByte: TJavaArray<Byte>;
  InetAddress: JInetAddress;
begin
  if (TJByteOrder.JavaClass.nativeOrder.equals(TJByteOrder.JavaClass._GetLITTLE_ENDIAN)) then
    IPAddress:= TJInteger.JavaClass.reverseBytes(AIntegerIPAddress)
  else
    IPAddress:= AIntegerIPAddress;
    
  SystemByte:= TJBigInteger.JavaClass.valueOf(IPAddress).toByteArray;
    
  try
    InetAddress:= TJInetAddress.JavaClass.getByAddress(SystemByte);
    
    Result:= JStringToString(InetAddress.getHostAddress);
  except
    Result:= 'Convert error';
  end;
end;