function LongIP(IP : string) : string;
var
IPaddr : array[1..4] of integer;
temp : string;
res : Longword;
i : integer;
begin
temp := ip;
temp := temp + '.';
for i := 1 to 4 do
begin
ipaddr[i] := strtoint(copy(temp,1,pos('.',temp) - 1));
delete(temp,1,pos('.',temp));
end;
// Check the IP
for i := 1 to 4 do
begin
try
inttostr(ipaddr[i]);
except
result := 'Invalid IP address.';
exit;
end;
end;
res := (ipaddr[1] * $FFFFFF) + ipaddr[1] +
(ipaddr[2] * $FFFF) + ipaddr[2] +
(ipaddr[3] * $FF) + ipaddr[3] +
(ipaddr[4]);
result := inttostr(res);
end;
function shortIP(const S: string): string;
var
IP : integer;
A, B, C, D: byte;
begin
IP:=StrToInt(S);
A:=(IP and $FF000000) shr 24;
B:=(IP and $FF0000) shr 16;
C:=(IP and $FF00) shr 8;
D:=IP and $FF;
result:=Format('%d.%d.%d.%d', [A, B, C, D]);
end;
The anti OLE way of get url from an URL shortcut;-)
function GetURL(URL: TFilename): string;
var
ini: TIniFile;
begin
ini := TIniFile.Create(URL);
try
result := ini.ReadString('InternetShortcut', 'URL', '');
except;
result := '';
ini.Free;
ini := nil;
end;
if Assigned(ini) then
ini.Free;
end;
Author
Target
Keywords
Description
Icehawk
D1/D2/D3/D4/D5
IP, DWORD, Endian, Swap, DCC
Obtaining IP as/from DWORD
{dword to atom routine}
function dwtoa(dw: DWORD): string;
var
inaddr: TInAddr;
begin
asm
mov eax,dw; {move the int to the accumulation register}
BSWAP eax; {swap the high and low order word }
mov dw,eax; {move result back to dw variable }
end;
inaddr.S_addr:=dw;
result:=inet_ntoa(inaddr);
end;
{atom to dword routine}
function atodw(s: string): DWORD;
var
dw: DWORD;
begin
dw:=inet_addr(PChar(s));
asm
mov eax,dw; {move the int to the accumulation register}
BSWAP eax; {swap the high and low order word }
mov dw,eax; {move result back to dw variable }
end;
result:=dw;
end;