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 Change the display mode settings in code?
why we should use main in C
How many tables can be connected with joins in oracle at a time?
How to get the default Windows folders ?
How to Set the MaxPage property of the PrintDialog component?
Can we create stored procedures via Delphi or C++ Builder?
compare TProvider Component vs. Provider Property ?
How to make the TDateTimePicker display blank?
how can i add 2 numbers using delphi console application and also windows application , compare both program , reply immediatly
How to Display a 24 bit True Color bitmap image on a 256 color display?
what is SQL Parameter binding?
How to execute a stored procedure with TIBSQL?