How to Get the local internet machine name and IP address?
Answer Posted / 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 |
Post New Answer View All Answers
What does memory leak show in delphi?
How to Change the root key ?
How to change Kylix directory permissions for all users when installed as root?
How to close the CD Tray in code?
How to use the Lookup method to return values from multiple columns ?
How to Generate a Windows Console Application?
How to Open an explorer window to a given folder?
why Paradox slow on some computers and not on others ?
How to Create temporary canvas?
Where can we obtain the help file for the VtChart component?
what are the uses of Arrow and Function Keys ?
Why reusing or inheriting from a Remote Data Module is not a good idea?
How to Trap scrolling messages for the ScrollBars of a TScrollBox ?
How to Use an animated cursor?
How to set a custom CVS PServer port?