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


Please Help Members By Posting Answers For Below Questions

What does memory leak show in delphi?

431


How to Change the root key ?

1339


How to change Kylix directory permissions for all users when installed as root?

1278


How to close the CD Tray in code?

1311


How to use the Lookup method to return values from multiple columns ?

1190






How to Generate a Windows Console Application?

1370


How to Open an explorer window to a given folder?

1192


why Paradox slow on some computers and not on others ?

1130


How to Create temporary canvas?

1617


Where can we obtain the help file for the VtChart component?

2373


what are the uses of Arrow and Function Keys ?

1772


Why reusing or inheriting from a Remote Data Module is not a good idea?

1133


How to Trap scrolling messages for the ScrollBars of a TScrollBox ?

1381


How to Use an animated cursor?

1310


How to set a custom CVS PServer port?

1892