Forum > Windows

[Solved] Registry (Hex or int) to ip Address?

(1/2) > >>

TheLastCayen:
I am using

Lazarus 2.0.12
FPC 3.2.0
Windows 10

I need to read an IP Address from the registry. The IP has been written per a 3rd party software and it's part of that software configuration.

As an example, the value from the registry is:

1E32A8C0

1E = 30
32 = 50
A8 = 168
C0 = 192

So the ip address is 192.168.50.30 (not sure why they saved it in this order, probably a pile)
If I read the number as an integer, the value is 506636480.

From there, I am totally lost. It seems easier to use the Hex value in order to extract my ip and I know I can "Registry.ReadInteger", then convert using IntToHex((X), 8));. fpc don't seem really friendly to work with Hex value. I am not sure how to isolate the number in pair of 2 so I can get the ip address per section. I am not sure how to work with the decimal version either. I don't see any hex variable I can work with and I am not too familiar with pointers. 

Anyone can recommend a way to read this ip address or some documentation to  point me in the right direction?

Thank you

MarkMLl:
So it looks as though it's stored as a little-endian (i.e. x86 native format) 32-bit word. Try https://www.freepascal.org/docs-html/current/rtl/system/ntobe.html etc.

MarkMLl

winni:
Hi!

IP addresses in the Windows registry are from the type REG_SZ whichs is a zero terminated string.

So you should not look for integers/Dwords but for strings with 3 dots in it.

Winni

Bart:
From your example it looks like you need to parse is as (pseudocode).
Lo(LoWord(Value)) . Hi(LoWord(Value)) . Lo(HiWord(Value)) . Hi(HiWordValue))
This would give you (Value=1E32A8C0): 192.168.50.30

Bart

wp:
This is a simple converter:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function IPAddressFromInteger(x: LongInt): String;type  TIPAddress = packed record b1, b2, b3, b4: byte; end;begin  with TIPAddress(x) do    Result := Format('%d.%d.%d.%d', [b1, b2, b3, b4]);end;

Navigation

[0] Message Index

[#] Next page

Go to full version