How to Get the local internet machine name and IP address?
Answer / venu
function GetIPFromHost
(var HostName, IPaddr, WSAErr: string): Boolean;
type
Name = array[0..100] of Char;
PName = ^Name;
var
HEnt: pHostEnt;
HName: PName;
WSAData: TWSAData;
i: Integer;
begin
Result := False;
if WSAStartup($0101, WSAData) <> 0 then begin
WSAErr := 'Winsock is not responding."';
Exit;
end;
IPaddr := '';
New(HName);
if GetHostName(HName^, SizeOf(Name)) = 0 then
begin
HostName := StrPas(HName^);
HEnt := GetHostByName(HName^);
for i := 0 to HEnt^.h_length - 1 do
IPaddr :=
Concat(IPaddr,
IntToStr(Ord(HEnt^.h_addr_list^[i])) + '.');
SetLength(IPaddr, Length(IPaddr) - 1);
Result := True;
end
else begin
case WSAGetLastError of
WSANOTINITIALISED:WSAErr:='WSANotInitialised';
WSAENETDOWN :WSAErr:='WSAENetDown';
WSAEINPROGRESS :WSAErr:='WSAEInProgress';
end;
end;
Dispose(HName);
WSACleanup;
end;
| Is This Answer Correct ? | 1 Yes | 0 No |
How to Get a list of the available drives on a system?
How to do a locate on a non-indexed field?
How do I close a modal form? For that matter, what is the best way to close any form?
How to Converta RGB color to a CMYK color?
How to Save and load metafiles in a BLOB field without using DBImage ?
How to Add accelerator characters to TTabsheets?
How to draw using LoEnglish Mapping Modes?
How to Use additional data sets in expressions ?
How to Determine if you have Delphi v3.02 installed?
what are the different String Trim functions?
How to Send a message to all controls on a form 16-JUL-98?
'Cannot Load IDAPI Service Library' error. What does this error mean?